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;

相关推荐
Htht11112 分钟前
【Qt】之【Get√】【Bug】通过值捕获(或 const 引用捕获)传进 lambda,会默认复制成 const
数据库·bug
一棵树长得超出它自己1 小时前
数据库系统学习
数据库
小袁搬码1 小时前
PLSQLDeveloper配置OracleInstantClient连接Oracle数据库
数据库·oracle·pl/sqldeveloper
圈圈编码1 小时前
悲观锁和乐观锁
java·开发语言·sql·mysql
学习中的码虫1 小时前
MySQL提升
数据库·mysql
islandzzzz3 小时前
三表查询SQL怎么写?----小白初学+案例引入
数据库
卡布奇诺-海晨3 小时前
MySQL的MVCC机制
数据库·mysql
hao_wujing4 小时前
攻击模型的恶意行为检测
网络·数据库·php
秃头摸鱼侠5 小时前
MySQL查询语句(续)
数据库·mysql
MuYiLuck5 小时前
【redis实战篇】第八天
数据库·redis·缓存