mysql中写if not exists报错,求大神看看

mysql中写if not exists报错,求大神看看,第1张

mysql中不支持if not exists 像你那样的用法

mysql 用法:

1. 最常用的if not exists用法: create tableif not exists AA 如果表AA不存在(返回true)则创建表

2. select 语句中使用exists, 如:

select a.id,a.name from user where exists (select * from class where a.class_id = c.class_id)

3. insert into中使用not exists, 为了表中不插入重复语句,可以在insert into 中使用not exists进行判断,如果不存在相同的记录(not exists返回true)则插入,否则不执行,语句如下:

insert into tableA(id,name,start_time,ds)

select '1234','testName','2017-07-01 18:00:00','20170701 ' from dual WHERE not exists (select * from tableA

where instance_id = '1234' )

语法结构就有问题,if判定的话需要在存储过程里面。你的这个写法应该是:

insert into 

    code_value(code,value,type,source) 

    values('1','1','1','2')

FROM dual

where

NOT EXISTS(SELECT * FROM code_value WHERE code = '331' AND type = 'AcceptPaymentType' AND source = 2)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6240420.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-18
下一篇 2023-03-18

发表评论

登录后才能评论

评论列表(0条)

保存