Creating a table and referencing that table in same package. [message #608373] |
Wed, 19 February 2014 04:53 |
|
skbytes
Messages: 21 Registered: February 2014 Location: Chester
|
Junior Member |
|
|
Hi Guys,
I'm creating a PL/SQL package and I want dynamically creates a number of tables in the database using the EXECUTE IMMEDIATE statement in my package before processing data into those tables.
I want to then reference these tables as a PL/SQL table ROWTYPE (see below).
TYPE l_record IS TABLE OF LIQ_HOLDING%ROWTYPE;
l_table L_RECORD;
Obvisouly the package won't compile because the LIQ_HOLDING table that I'm creating doesn't exist at the time the package compiles.
How do I get around this problem? would I have to create a type record which replicates the LIQ_HOLDING table?
Any suggestions to a solution to this problem would be great.
|
|
|
|
|
|
|
|
|
Re: Creating a table and referencing that table in same package. [message #608382 is a reply to message #608380] |
Wed, 19 February 2014 05:25 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Why would joining a few tables to retrieve a few million rows cripple performance? Why would there be any memory problems? Why isn't normal SQL enough? If you must do row-by-row processing, why not use a cursor?
I am sorry because it sounded an interesting problem, but I do not think I can assist without knowing what you are trying to do and what the problem is.
|
|
|
|
|
|
|
|
Re: Creating a table and referencing that table in same package. [message #608394 is a reply to message #608393] |
Wed, 19 February 2014 06:04 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
skbytes wrote on Wed, 19 February 2014 12:56When you say permanently create a global temporary table, isn't that the same as creating a normal table and dropping the normal table at the end of the batch process?
No, it is not. Read about it in the link gazzag provided, or the ones below in my post.
skbytes wrote on Wed, 19 February 2014 12:56But the question is can I dynamically create a table whether it be normal or temporary in a PL/SQL package that I reference a variable PL/SQL ROWTYPE of that table,
You can create. You cannot reference.
skbytes wrote on Wed, 19 February 2014 12:56Or is it a case of creating a PL/SQL record that replicates the structure of the holding table and use that PL/SQL as the ROWTYPE.
How will you (and hence Oracle) obtain the structure of non-existing table?
Generally, the correct solution depends on realizing what is dynamic on those "dynamic tables".
If it is their structure (columns - count and/or data types), you have a serious problem referencing them and decrypting their meaning anywhere.
If it is their data (rows), then (as many others said) create that table(s) only once before package creation as global temporary one(s).
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:48812348054
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1164655862293
You will be able to "reference" the table(s) simultaneously - other parallel processes will not fail creating the already existing table, each of them will see only its own data.
Quote: DO NOT dynamically create them, DO NOT dynamically create them,
please -- do NOT dynamically create them.
|
|
|
|
|
|
|
|
|
|
|
|
Re: Creating a table and referencing that table in same package. [message #608415 is a reply to message #608409] |
Wed, 19 February 2014 08:47 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
skbytes wrote on Wed, 19 February 2014 14:10Hi Cookiemonster, the package will be recompiled the next time it's executed with the SQL table creation script. But it's a good point and i'll talk to the DBA and maybe just truncated the temporary (now perm tables I guess) tables once the process is finished rather than drop them.
You need to read up on global temp tables because you're worrying about non existent problems.
A GTT holds data either for the life of a transaction or the life of a session depending on how it's set up, once that's done all data it held disappears without you having to do a thing.
It's not going to be holding big chunks of memory / disk space between runs.
|
|
|
|
|