1 create procedure gh() #注意各個地方的分號!此代碼應先運行除掉最后一句的部分,然后運行call gh顯示已經存儲的結果 2 BEGIN 3 declare c_no int; #聲明數據類型的方法 4 5 select count(*) into c_no # 將一個結果存入一個變量 6 from jyb 7 where jszh in( 8 select jszh 9 from dzb 10 where dw = '經濟系'); 11 12 if c_no = 0 then #if......then......else.....end if 13 select xm as 姓名,dw as 所在單位,zc as 職稱 14 from dzb 15 where dw = '經濟系' and 16 not exists ( 17 select * 18 from jyb,dzb 19 where dzb.jszh = jyb.jszh and dw = '經濟系'); 20 21 else 22 select '此系還有人沒有還書'; #此處select相當於print 23 24 END if; 25 END 26 27 28 call gh;