if exists(select 1 from User_Tables t where t.table_name='test') then
execute immediate 'drop table test';
end if;
建表语句;
execute immediate 'drop table test';
end if;
建表语句;
解决方案 »
- 请教oracle一个自定义聚合函数 aggregate function 的问题,十分感谢!
- sqlserver与Oracle同步
- ORA-00106: 无法在连接到调度程序时启动/关闭数据库
- 统计报表问题
- RATIO_TO_REPORT()OVER()函数如何解决百分比问题
- 小弟请教 database links 的问题
- 游标出错
- 帮忙写一条SQL,急切!!!
- oracle 11gr2安装时如何才能选择下面的rac
- windows server 2008 R2系统下Oracle VM VirtualBox不能为虚拟电脑打开一个新任务?
- 请教imp的用法,只导入部分数据
- 请教快照和JOB不能自动刷新的问题!
SP2-0734: 未知的命令开头 "if exists(..." - 忽略了剩余的行。
BEGIN immediate 'drop table TEST'; END; *
ERROR 位于第 1 行:
ORA-06550: 第 1 行, 第 17 列:
PLS-00103: 出现符号 "drop table TEST"在需要下列之一时:
:= . ( @ % ;
符号 ":=" 被替换为 "drop table TEST" 后继续。
SP2-0042: 未知命令"end if" -- 其余行忽略。
create table TEST (
*
ERROR 位于第 1 行:
ORA-00955: 名称已由现有对象使用
要用也只能用case when
但是在SQL语句里也不能用drop,所以还是只能用存储过程来写。
if exists(select 1 from User_Tables t where t.table_name='test') then
execute immediate 'drop table test';
end if;
end;
所以不能写 if exists(...)可以这么写:
declare v_count number := 0 ;
begin
select 1 into v_count from User_Tables t where t.table_name=upper('test') ;
execute immediate 'drop table test';
exception
when no_data_found then
dbms_output.put_line('There is no table before create;');
end ;