insert into stu (id,name)
select ‘1’,‘小明’
from dual
where not exist(
select id,name
from stu
where
id=‘1’
and name = ‘小明’
)
在insert into stu (id,name) 之后增加了一个select语句,这个语句代表着查询小明的信息是否在stu 表中;
dual是一张虚拟表,select …from …;
格式:select sysdate from dual;
在where后面exist代表着是否存在,如果之后的sql成立则执行insert,不成立则不执行insert;
有条件地向表中插入数据
最新推荐文章于 2022-09-20 23:24:10 发布