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;

相关推荐
小猿姐1 小时前
KubeBlocks AI:AI时代的云原生数据库运维探索
数据库·人工智能·云原生·kubeblocks
NocoBase2 小时前
10 个开源工具,快速构建数据应用
数据库·低代码·开源
麻辣清汤3 小时前
结合BI多维度异常分析(日期-> 商家/渠道->日期(商家/渠道))
数据库·python·sql·finebi
钢铁男儿3 小时前
Python 正则表达式(正则表达式和Python 语言)
python·mysql·正则表达式
Kan先生4 小时前
对象存储解决方案:MinIO 的架构与代码实战
数据库·python
超级迅猛龙4 小时前
保姆级Debezium抽取SQL Server同步kafka
数据库·hadoop·mysql·sqlserver·kafka·linq·cdc
杨过过儿5 小时前
【Task02】:四步构建简单rag(第一章3节)
android·java·数据库
····懂···6 小时前
攻克PostgreSQL专家认证
数据库·postgresql
每天都在想吃啥6 小时前
day31 SQLITE
数据库·sqlite
helloyaren6 小时前
Docker Desktop里搭建Mysql 9.4主从复制的保姆级教程
mysql·技术·主从复制