如何编写PL/SQL
程序:
ts
答案 0 :(得分:5)
您需要使用动态SQL来实现此目的。
create or replace procedure clone_table
( p_copy_table in varchar2
, p_new_table in varchar2
, p_inc_data in varchar2 := 'Y' )
is
stmt varchar2(32767);
begin
stmt := 'create table '|| p_new_table
|| ' as select t.*, systimestamp as ts '
|| ' from ' || p_copy_table || ' t';
if p_inc_data != 'Y' then
-- use a empty resultset to create an empty table
stmt := stmt || ' where 1=0';
end if;
execute immediate stmt;
end;