mysql存储过程中
下面是一个较常见的场景,判断表中某列是否存在某值,如果存在执行某操作
需要注意的是不能用if exists;
exists可以在where后面或者在create object是使用,但是在if语句中不可以使用,只能用变通的方法。
?
delimiter $$ create procedure proc_add_book( in $bookName varchar (200), in $price float ) begin declare $existsFlag int default 0; select bookId into $existsFlag from book where bookName = $bookName limit 1; if bookId > 0 then #if not exists ( select * from book where bookNumber = $bookName) then insert into book(bookNumber,price) values ($bookName,$price); end if; end $$ delimiter ; |
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦