IBM Db2 中 if 存在的语法 [英] Syntax of if exists in IBM Db2
本文介绍了IBM Db2 中 if 存在的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果表存在,则后续查询将删除该表,但它似乎不适用于 IBM Db2.
The follow query drops a table if the table exists but it doesnt seem to work for IBM Db2.
Begin atomic
if( exists(
SELECT 1 FROM SYSIBM.SYSTABLES
WHERE NAME='EMAIL' AND TYPE='T' AND creator = 'schema1'
)) then
drop table EMAIL;
end if;
End
如果我有 DML 语句而不是 table drop 语句,则相同的 if exists 语法有效.对此的任何帮助表示赞赏
Whereas the same if exists syntax works if i have a DML statement instead of table drop statement. Any help on this is appreciated
更新 1:我读到您无法在 begin atomic 块中运行 DDL 语句,因此我的第一个语句失败但第二个语句正常.
Update 1: I read that you cannot run DDL statement within begin atomic block hence my first statement fails but the second goes fine.
推荐答案
我的做法如下
Begin atomic
if( exists( SELECT 1
FROM SYSIBM.SYSTABLES
WHERE NAME='EMAIL' AND TYPE='T' AND creator = 'schema1'
)
)
then customStoredproc('drop table EMAIL');
end if;
End
我的 customStoredProc 只有一个 stmt 立即执行 @dynsql;
My customStoredProc just has one stmt execute immediate @dynsql;
这篇关于IBM Db2 中 if 存在的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文