• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

mysql 存储过程读书笔记(一)基础

mysql 搞代码 7年前 (2018-06-06) 146次浏览 已收录 0个评论

mysql 存储过程读书笔记(1)基础

mysql存储过程目前只支持存储过程,存储函数,触发器

存储过程基本结构:

Create procedure ProcedureName(Params[in,out])

Begin

     Declare  attr attrType;

     procedure content;

End;

 

Example:

1. 创建基本存储过程

create procedure exampe1()
begin
      declare l_student_count integer;
      select count(*) into l_student_count from student;
 
       select concat(‘there are totally ‘, l_student_count ,’ students’);
end;

 

2.删除存储过程

   drop procedure example1;

 

3.创建带入参的存储过程

create procedure example2(stu_id int)
begin
    declare stu_name varchar(30);
 
     select name into stu_name from student where student_id = stu_id;
     select stu_name;
end;

 

4.创建函数基本结构

create function example5() returns int
begin
     declare student_count int;
 
      select count(*) into student_count from student;
      return student_count;
end;

 

5.创建触发器基本结构

create trigger example6 before update on t for each row
begin
   If New.percent < 0 then
     set New.percent = 20;
   Else
     set New.percent = 100;
   End If;
End;


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:mysql 存储过程读书笔记(一)基础

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址