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;

相关推荐
duration~1 小时前
PostgreSQL并发控制
数据库·postgresql
给力学长2 小时前
自习室预约小程序的设计与实现
java·数据库·vue.js·elementui·小程序·uni-app·node.js
迷茫运维路3 小时前
MySQL5.7主从延迟高排查优化思路
数据库·主从延时高
菜鸟学Python3 小时前
Python web框架王者 Django 5.0发布:20周年了!
前端·数据库·python·django·sqlite
小云数据库服务专线4 小时前
GaussDB 查看会话连接数
数据库·gaussdb
墨迹的陌离5 小时前
【Linux】重生之从零开始学习运维之Mysql
linux·运维·服务器·数据库·学习·mysql
BigBigHang6 小时前
【docker】DM8达梦数据库的docker-compose以及一些启动踩坑
数据库·docker·容器
m0_720245016 小时前
QT(四)基本组件
数据库·qt·microsoft
葡萄城技术团队7 小时前
利用 SQL Server 实现字符替换的高效函数
sql
Databend7 小时前
使用 Databend Cloud 归档 OceanBase 数据数据库
数据库