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;

相关推荐
春生野草4 分钟前
SpringBoot配置文件
java·数据库·spring boot
奇点 ♡15 分钟前
MySQL基础题
数据库·sql·mysql
cherry523025 分钟前
Java大厂面试真题:Spring Boot + 微服务 + 缓存架构三轮技术拷问实录
jvm·spring boot·mysql·微服务·java面试·分布式架构·redis缓存
唐古乌梁海32 分钟前
【mysql】MySQL 数据库迁移
数据库·mysql·adb
啊吧怪不啊吧36 分钟前
SQL之表的时间类内置函数详解
大数据·服务器·数据库·sql
2503_9284115640 分钟前
11.5 包和包管理器
数据库·arcgis·node.js·编辑器
JanelSirry1 小时前
真实场景:防止缓存穿透 —— 使用 Redisson 布隆过滤器
数据库·mysql·缓存·redisson·布隆过滤器
mmm.c1 小时前
mysql启动提示1067:进程意外终止
数据库·mysql
埃泽漫笔1 小时前
Redis单线程还是多线程?
数据库·redis·缓存
虎子_layor1 小时前
PostgreSQL这么多优势,为什么还要使用MySQL
后端·sql