Click here to Skip to main content
15,888,202 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to use a temporary variable in oracle function, but the function is not accepting the table, can any provide me the syntax to create and use temporary table in oracle function.

I used following code in function

SQL
create global temporary table store_sales 
on commit delete rows 
as select * from tbl_folders


but i am getting following error
C#
Compilation failed,line 17 (18:44:28)
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge



Thank you.
Posted
Updated 10-Nov-17 0:45am
Comments
George Jonsson 3-Dec-15 20:46pm    
What does the code before the CREATE statement look like?

You cannot use DDL inside a function.

Simply create the temp table and let it exist in your tablespace. All data you insert into it will be usable from that session only. So there is no need to create and delete it for every transaction.
So you can just use:
SQL
INSERT INTO store_sales 
select * from tbl_folders
Since you have specified on commit delete rows, the data will be automatically deleted when you commit or rollback the transaction.
 
Share this answer
 
I Have use below code and successfully work.
Below statement for creation of global temporary table.

SQL

CREATE global TEMPORARY TABLE xx_am_temp_tbl_emp2
on commit delete rows as select employee_id, first_name from XX_am_employees;

Result : Global temporary TABLE created.
 
Share this answer
 
v2
Comments
Jochen Arndt 10-Nov-17 7:21am    
The question is two years old and you missed that he tried to create the table inside a function which is not allowed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900