各位早上好,先看今天的英语内容:
Family Gathering 家庭聚会
red packets 红包
Buddhism
The Drag Boat Festival 端午节
Laba Rice Porridge Festival 腊八节
Valentine Day 情人节
the violin 小提琴
badminton 羽毛球
have to do with 与...有关
eg: What does that have to do with me? 那和我有什么关系?
I called my friend. 我打电话给朋友
I chated with my friend. 我与朋友聊天
chat online 在线聊天
wash up 洗脸,洗手
今天的正式内容为:存储过程。
提起存储过程,熟悉数据库的人肯定不会陌生。那么今天,我们就好好扒一扒存储过程。什么是存储过程呢?简单地说,存储过程是一种封装了SQL的语句集,并能实现相应的逻辑功能。当存储过程执行成功后会被存储在数据库服务器中,并允许客户端直接调用,这大大提高了SQL语句的执行效率和安全性。下面,我们来看看如何使用存储过程。
创建存储过程:
create procedure 存储过程名称([[in|out|inout] param_name type[,...]])
begin
存储过程具体逻辑
end
存储过程的参数分为IN、OUT、INOUT类型,分别表示输入类型参数、输出类型参数以及输入输出类型参数。IN是默认的参数类型;OUT表示输出类型参数,即它可以把存储过程内部的数据传递给调用者;而INOUT类型参数既可以把数据传入到存储过程中,也可以把存储过程的数据传递给调用者。
好了,我们具体看看如何创建存储过程吧:
1.无参的存储过程的创建
delimiter //
create procedure my_proc()
begin
update scoreinfo set remark='优秀' where scores>=90;
end //
delimiter ;
如何调用呢?
call my_proc();
调用此存储过程后,分数超过90分的remark字段都会被修改为'优秀'。
2.创建带有IN类型参数的存储过程
delimiter //
create procedure my_proc(in param int)
begin
if (param is not null) then
update scoreinfo set remark='一般' where scores<=70;
end if;
end //
delimiter ;
调用此存储过程:call my_proc(1)
3.创建带有out 类型参数的存储过程
delimiter //
create procedure my_proc(out param int)
begin
select count(*) into param from scoreinfo;
end //
delimiter ;
调用此存储过程:call my_proc(@x);
查询用户变量x的值: select @x;
4.创建带有inout类型参数的存储过程
delimiter //
create procedure my_proc(inout param int)
begin
if (param is not null) then
select count(*) into param from scoreinfo;
end if;
end //
delimiter ;
调用此存储过程:
set @a=1 ;
call my_proc(@a) ;
select @a;
先给用户变量a赋值为1,然后调用存储过程并将a传入,最后查询用户变量a的值。
今日进京,冲啊!