mysql存储过程创建与删除(参数输入输出)

-- 存储过程的高级应用

-- 对表itpux_yg中的用户名进行模糊查询

select * from itpux_yg;

drop procedure sp_yg01;

delimiter $$

create procedure sp_yg01(in spname varchar(30))

begin

if spname is null or spname='' then

select * from itpux_yg limit 2;

else

select * from itpux_yg where name like spname;

end if;

end

delimiter ; call sp_yg01(null); call sp_yg01('%10125%'); call sp_yg01('%10123%'); -- 存储过程输入输出参数 in:输入参数,并应用到存储过程中使用。 out:输出参数,从存储过程中传出一个值。 inout:输入又输出 -- 案例2:返回员工表工资中的最大值、最小值、平均值。 drop procedure sp_yg_sal; delimiter // create procedure sp_yg_sal( out salmax decimal(8,2), out salmin decimal(8,2), out salavg decimal(8,2)) begin select MAX(salary) into salmax from itpux_yg; select MIN(salary) into salmin from itpux_yg; select AVG(salary) into salavg from itpux_yg; end // delimiter ; call sp_yg_sal(@salmax,@salmin,@salavg); select @salmax; select @salmin; select @salavg; -- 存储过程中对输出变量的赋值语句: select 列名1 into 变量名1 from 表,条件是什么 -- 案例3:输入员工工号,要知道这个员工一年所有的工资。-- inout参数 drop procedure sp_yg_sal365; delimiter

create procedure sp_yg_sal365(

in ygid int,

out sal365 decimal(10,2))

begin

select SUM(salary*12+salary*5) from itpux_yg yg where yg.`JOBID`=ygid into sal365;

end

delimiter ; call sp_yg_sal365(10003,@sal365); select @sal365;

相关推荐
W.Buffer2 分钟前
通用:MySQL主库BinaryLog样例解析(ROW格式)
android·mysql·adb
W.Buffer16 分钟前
通用:MySQL-InnoDB事务及ACID特性
数据库·mysql
he___H18 分钟前
尚庭公寓中Redis的使用
数据库·redis·缓存·尚庭公寓
菜鸟plus+2 小时前
Java 定时任务
数据库·oracle
DemonAvenger2 小时前
Redis HyperLogLog 深度解析:从原理到实战,助你优雅解决基数统计问题
数据库·redis·性能优化
Hello.Reader2 小时前
Apache StreamPark 快速上手从一键安装到跑起第一个 Flink SQL 任务
sql·flink·apache
潘潘潘潘潘潘潘潘潘潘潘潘2 小时前
【MySQL】库与表的基础操作
数据库·mysql·oracle
W.Buffer7 小时前
通用:MySQL-深入理解MySQL中的MVCC:原理、实现与实战价值
数据库·mysql