关于IF EXISTS

elated 2011-03-01 05:14:05

begin
if exists(select * from user_tables where table_name = 'TMP_ST') then
execute immediate 'drop table TMP_ST';
end if;
end;


这段SQL为什么会报错?

错误显示"function or pseudo-column 'EXISTs' may be used inside a SQL statement only"

exists只能用在sql语句里?
...全文
90 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
elated 2011-03-02
  • 打赏
  • 举报
回复
明白了
  • 打赏
  • 举报
回复
--oracle不是这样的语法 
declare
cnt number;
begin
select count(*) into cnt from user_tables where table_name = 'TMP_ST';
if cnt>0 then
execute immediate 'drop table TMP_ST';
end if;
end;
kingkingzhu 2011-03-01
  • 打赏
  • 举报
回复
の 好像没见过额 学习了

select count(*) into l_row from user_tables where table_name = 'TMP_ST';
if l_row >0 then
execute immediate 'drop table TMP_ST';
end if;
gelyon 2011-03-01
  • 打赏
  • 举报
回复

--你的写法是MSSQL的语法,Oracle不支持
declare
cnt number;
begin
select Count(*) into cnt from user_tables where table_name = 'TMP_ST' ;
if cnt>0 then
execute immediate 'drop table TMP_ST';
end if;
end;

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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