db2 - 不存在导致插入问题的地方,db2

标签 db2

我有一个这样的查询:

insert into mySchema.myTable (award_id, cust_id) values ('blahblah', 12345)
where not exists (select * from mySchema.myOtherTable where cust_id = 12345);

我收到错误:

ILLEGAL USE OF KEYWORD WHERE.  TOKEN FOR <END-OF-STATEMENT> NOT ATOMIC WAS EXPECTED SQL 
Code: -199, SQL State: 42601

我看到一堆类似的查询被接受为答案,但我不明白为什么会发现这个问题。

最佳答案

这将起作用:

insert into mySchema.myTable (award_id, cust_id) 
select 'blahblah', 12345
from sysibm.sysdummy1
where not exists (select * from mySchema.myOtherTable where cust_id = 12345);

sysibm.sysdummy1 的替代方法是:

insert into mySchema.myTable (award_id, cust_id) 
select 'blahblah', 12345
from ( values (1) )
where not exists (select * from mySchema.myOtherTable where cust_id = 12345);

关于db2 - 不存在导致插入问题的地方,db2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24068016/

相关文章:

Android 应用程序连接到 db2

mysql(使用db2)多对多获取具有给定参数的所有记录

sql - DB2/iSeries SQL 清理 CR/LF、选项卡等

sql - 查询 : The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use 时出错

db2 - 为DB2配置SQuirreL

bash - 检测 db2 死锁的脚本

linq-to-entities - 在 DB2 中使用 LINQ to Entity Framework

sql - sqoop如何在将数据导入到hive时自动从db2中修剪一些字符类型列?

linux - 包含 '$' 的 db2 命令行处理器和密码

sql - 现有 DB2 列报告为不是表的列