ORACLE里如何在drop前判断表是否存在

mor 2006-03-08 02:22:58
这样写不成:
if exists (select * from tabs where table_name='test_table') then
drop table test_table;
end if;

表存在的时候不报错,不存在的时候报错:ORA-00942: table or view does not exist

是IF写的不对?
...全文
404 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mor 2006-03-08
  • 打赏
  • 举报
回复
嗯,我在查询工具里这样写可以执行,但是要用exp,好像不能declare
票票飞扬 2006-03-08
  • 打赏
  • 举报
回复
不能这样写
直接drop就可以

declare
w_count int;
w_name varchar2(20);
begin
w_name := 'tablemname';
select count(*) into w_count from user_tables where name=w_name;
if (w_count>0) then
execute immediate 'drop table '|| w_name;
end if;
end;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧