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;

相关推荐
爱喝水的鱼丶5 分钟前
SAP-MM:SAP采购组织全面学习指南:从概念到实战配置图解
运维·开发语言·数据库·学习·sap·mm模块·采购组织
深鱼~41 分钟前
DbGate数据库管理新方案:cpolar打造跨平台远程访问通道
数据库
WAWA战士1 小时前
mysql总结
数据库
熊思宇1 小时前
Sqlite“无法加载 DLL“e_sqlite3”: 找不到指定的模块”解决方法
数据库·sqlite
往事随风去1 小时前
面试官:mysql从数据库断开一段时间后,部分binlog已丢失,如何重建主从?
运维·数据库·mysql
J.Kuchiki1 小时前
【PostgreSQL内核学习 —— (SeqScan算子)】
数据库·postgresql
酷酷的崽7982 小时前
Redis 键(Key)的命令
数据库·redis·缓存
189228048612 小时前
NW622NW623美光固态闪存NW624NW635
大数据·网络·数据库·人工智能·microsoft·性能优化
云飞云共享云桌面2 小时前
1台电脑10个画图设计用怎么实现
linux·运维·服务器·网络·数据库·自动化·电脑
TTBIGDATA2 小时前
【Ambari监控】Ambari-Metrics 的分支研究
大数据·数据库·hadoop·ambari·bigtop·edp·hidataplus