plsql - Created Temporary Tables Dynamically -
i have scenario like, need create stored procedure in columns come dynamically. based upon columns temporary tables should created. actually, scenario did in sql server , have migrated sql server database oracle.
thanks
if want create table dynamically, you'd need use dynamic sql
begin execute immediate 'create global temporary table table_name( col1 number, col2 number )'; end;
that being said, mistake directly port sql server code creates temporary tables oracle. not work same way sql server code does.
- first off, temporary tables in oracle visible every session unlike sql server local session. means if have 2 sessions calling stored procedure, they'd both try create temporary table , second 1 fail (things worse assuming dropping temporary table @ end of procedure rather letting thousands of temporary tables accumulate).
- creating tables inefficient process in oracle given amount of latching required. oracle's assumption not creating objects on fly. if application violates assumption, encounter scalability issues.
- if create tables on fly, you'll have refer them on fly. queries against temporary tables need use dynamic sql. less efficient static sql , makes code harder write, harder debug, , harder maintain.
Comments
Post a Comment