一点示例明白mysql存储过程
</pre></div><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; line-height: 21px;"><span style="font-size:18px;"><span style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; line-height: 37.894737243652344px;">封装sql:</span></span><!--EndFragment--></div><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; line-height: 21px;"><span style="font-size:18px;"><span style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; line-height: 37.894737243652344px;"></span></span><pre name="code" class="sql">create procedure p1() begin select * from t_news; end $ //mysql存储过程 简单实例显示存储过程信息: \G (横向表格采用纵向表格输出)
<span style="font-size:18px;">create procedure p2(n int) #含参 begin select * from t_category where cid > n; end $ </span>
<span style="font-size:18px;">create procedure p3(n int, j char(1)) #含参 begin if j='h' then #与其他语言不同 必须加then 注意符号= 不是== select * from t_category where cid > n; else select * from t_category where cid <n; end if; end $ </span>
create procedure p4(n smallint) #含参 begin declare i int; declare s int; set s = 0; set i = 1; while i<=n do set s =s+i; set i=i+1; end while; select s; end $
<img src="" alt="" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; background-color: rgb(255, 255, 255);" />
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。