我有一个这样的查询:
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/