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 小时前
Django 响应对象、文件上传与类视图
数据库·django·sqlite
努力的小雨2 小时前
同一份 SQL 跑多套环境:Ksql 变量怎么用才安全
数据库
ltl2 小时前
数据库作为 LLM 记忆体:语义缓存、RAG 与一致性
数据库
ltl2 小时前
WAL 与崩溃恢复:ARIES 协议怎么跑通
数据库
ltl3 小时前
TEE 数据库:EnclaveDB、Oblivious 原语与机密 SQL
数据库
麻瓜code4 小时前
【Mysql】重新学一遍 SQL 执行顺序
数据库·sql
这个DBA有点耶4 小时前
数据库一体机架构演进:从硬件堆叠到软硬深度耦合
服务器·网络·数据库·硬件架构·运维开发·database·数据库架构
一只fish4 小时前
优化器架构对比:Oracle vs PostgreSQL vs MySQL
mysql·postgresql·oracle
安_5 小时前
RAG的向量数据库:为LLM提供语义搜索能力
数据库
喜欢的名字被抢了6 小时前
程序出问题怎么查,以及如何让它不掉线
java·运维·数据库