【发布时间】:2019-05-22 17:14:38
【问题描述】:
我正在尝试运行两个查询,其中只有第一个不为空时才会运行第二个查询。比如:
if((select * from abc where id =1)!=null)
select * from cde
else exit;
执行此类操作的正确方法是什么?
【问题讨论】:
标签: mysql if-statement stored-procedures
我正在尝试运行两个查询,其中只有第一个不为空时才会运行第二个查询。比如:
if((select * from abc where id =1)!=null)
select * from cde
else exit;
执行此类操作的正确方法是什么?
【问题讨论】:
标签: mysql if-statement stored-procedures
使用存在条件
只有select 1 from abc where id =1返回至少一条记录select * from cde才会被执行
select * from cde
where exists (select 1 from abc where id =1 )
如果你需要执行其他语句,你可以使用类似下面的语句
if exits (SELECT 1 from abc where id =1) then
-- select a into var_x from cde...
-- upddate ...
else
--
end if;
【讨论】: