Thursday, March 29, 2012

Adding a sysdate to a tablename

Hi basically Im creating a package and I need to back up the table and put the date in the name of the table whenever the package is run, however I get an error when I try and do it, I think it should be possible but im not sure:

SELECT *
INTO tablename + CONVERT(char(10), GETDATE(), 112)
FROM tablename

So the tablename should looksomething like this

tablename20031210

The error message is: incorrect syntax near +

Can anybody help.

ThanksUse dynamic Sql within pl/sql:

l_statement varchar2(100);
begin
l_statement:=' create table name_'||to_char(sysdate,'DDMMRRRR');
l_statement:=l_statement||define colums here

execute immediate l_statement;
end;

eventually you must append an ; at the end of the varchar2 because it is an DDL-Statement

No comments:

Post a Comment