当前位置:Gxlcms > 数据库问题 > mySQL语法中的存储过程及if语句的使用简例

mySQL语法中的存储过程及if语句的使用简例

时间:2021-07-01 10:21:17 帮助过:27人阅读

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;

 

 

mySQL语法中的存储过程及if语句的使用简例

标签:logs   sel   from   存储过程   bsp   代码   声明   div   单位   

人气教程排行