我想通过附加 SYSDATE
来更改表名到它。比如我想换表EXAMPLE_TABLE
至 EXAMPLE_TABLE_05_01_2015
,但我想从 SYSDATE
获取日期.
我准备了以下内容,但它不起作用:
ALTER TABLE "MYDB"."EXAMPLE_TABLE" rename to (SELECT 'EXAMPLE_TABLE' || TO_CHAR(SYSDATE, '_dd_MM_yyyy') FROM DUAL);
我怎样才能让它工作?
这是错误:
SQL Error: ORA-14047: ALTER TABLE|INDEX RENAME may not be combined with other operations
14047. 00000 - "ALTER TABLE|INDEX RENAME may not be combined with other operations"
*Cause: ALTER TABLE or ALTER INDEX statement attempted to combine
a RENAME operation with some other operation which is illegal
*Action: Ensure that RENAME operation is the sole operation specified in
ALTER TABLE or ALTER INDEX statement;
最佳答案
使用 execute immediate
.
begin
execute immediate
'alter table mydb.example_table rename to ' ||
'example_table_' || to_char(sysdate, 'dd_mm_yyyy');
end;
/
也就是说,我有一种预感,您最好使用分区表。
关于sql - 使用 sysdate 更改表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27777242/