• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

dynamic DDL

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to create a temporary table to hold data from an existing table using the following code:
declare
begin
execute immediate 'create table test_tmp as select * from test where col1 >= :create_date' USING SYSDATE ;
end;
/
when I run it using sqlplus I get the following message:
ERROR at line 1:
ORA-01027: bind variables not allowed for data definition operations
ORA-06512: at line 3

Can somebody help me with it?
Thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:create_date
It states that you can't use a bind variable in a DDL statement.
You could try the long way.
Use the create table, with the where clause being 1=2 so that it creates a table with the correct columns.
Then create a cursor for the dynamic query. You can use bind variables here.
Then loop through the cursor and insert the data into the new table.
Mark
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because you use the EXECUTE IMMEDIATE statement you can also leave the bind variable out of it.
E.G.

You then just past in the date and Oracle will treat the whole as a string and parse it and you won't use any bind variables.
Regards,
Robert
[ July 11, 2003: Message edited by: Robert Willems ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic