我尝试创建存储过程,然后检查是否存在表,然后重新创建。
create or replace procedure Checktableexist
(p_tab_name in all_tables.table_name%type)
authid definer
is
n pls_integer;
begin
SELECT count(*) into n FROM all_tables where table_name = p_tab_name;
if n = 1
then
-- no need to specify schema because it's the procedure owner
execute immediate 'drop table '|| p_tab_name;
end if;
execute immediate 'create table p_tab_name as select * from xvz WHERE 1=0';
end Checktableexist;
/
exec Checktableexist(' abc1')
我收到以下错误:
BEGIN Checktableexist('abc1'); END;
Error at line 1
ORA-00955: name is already used by an existing object
ORA-06512: at "ADMIN.CHECKTABLEEXIST", line 17
ORA-06512: at line 1
答案 0 :(得分:0)
您正在创建表p_tab_name
,而不是将其用作变量。把它从字符串文字中删除,你应该没问题:
execute immediate
'create table ' || p_tab_name || ' as select * from xvz WHERE 1=0';