当前位置:网站首页>Mysql 存储过程详解(procedure)
Mysql 存储过程详解(procedure)
2022-08-03 05:22:00 【鱼丸丶粗面】
1 概述
2 语法
2.1 创建
create procedure 存储过程名(in|out|inout 参数名 参数类型)
begin
-- 变量定义
declare v_int int default 0;
-- 变量赋值
set v_var = 1;
-- 具体逻辑
...;
end;
实例:
use test; -- 指定执行用户
drop procedure if exists procedure_demo; -- 若存在,先删除
delimiter $$ -- 指定分隔符,避免与逻辑代码中的 ";" 产生冲突
-- 创建存储过程
create procedure procedure_demo(in i_int int,
out o_varchar varchar(255))
begin
-- 变量定义
declare v_int int default 0;
declare v_numeric numeric(10, 2) default 13.14;
declare v_date date default '2021-05-10';
declare v_datetime datetime default '2021-05-10 21:03:00';
declare v_varchar varchar(255) default '存储过程模板';
-- 变量赋值
set v_int = i_int;
-- 逻辑代码
select v_int,
v_numeric,
v_date,
v_datetime,
v_varchar
from dual;
-- 输出,y: 执行成功
set o_varchar = 'Y';
end $$
delimiter ; -- 还原默认分隔符 ";"
2.2 调用
-- 有参数: 入参, 出参
call procedure_demo(2, @v_out);
select @v_out;
-- 无参数
call procedure_name();
2.3 查询
-- 方式1:查询常规情况
show procedure status where db='数据库名';
-- 方式2:查询常规情况
select *
from information_schema.routines r
where r.routine_schema='数据库名'
and r.routine_type = 'PROCEDURE';
-- 方式3:查询定义的部分 create ...
show create procedure 数据库.存储过程名;
2.4 删除
drop procedure if exists procedure_demo; -- 若存在,先删除
边栏推荐
猜你喜欢
随机推荐
中国融资租赁行业市场投资分析与前景战略规划建议报告2022~2028年
【XSS,文件上传,文件包含】
The ` monorepo ` ` hoist ` mechanism lead to the change of the loading configuration file path
MySql 怎么查出符合条件的最新的数据行?
mysql 客户端SSL错误2026 (HY000)
【按位取反,逻辑操作符,条件操作符,逗号表达式,下标引用,函数调用,结构体】操作符后续+表达式求值(上)
详解背包问题(DP分支)
【HQL】(二) 查询使用正则表达式做列选择
【源码解读】你买的NFT到底是什么?
icebreaker的垃圾话学习指南
7.15(6)
【DC-2靶场渗透】
MySQL 安装报错的解决方法
中国聚氯乙烯(PVC)土工膜发展动态及投资前景预测报告2022~2028年
用pulp库解决运输问题【详细】
中国认证认可服务行业“十四五”发展规划及经营模式分析报告2022~2028年
【源码解读】火爆的二舅币真的跑路了吗?
MySQL EXPLAIN 性能分析工具详解
7.17(7)
Qlik Sense 字符串截取和拼接详解(Left、Right、&)