当前位置:网站首页>【MYSQL】存储过程的使用
【MYSQL】存储过程的使用
2022-06-11 10:23:00 【小艾同学~】
1.存储过程的使用
在使用存储过程前先了解一下什么是存储过程。
存储过程和函数
存储过程和函数:类似于java中的方法
好处:
1.提高代码的重用性
2.简化操作
含义:一组预先编译好的sql语句的集合,理解成批处理的语句
1.提高代码的重用性
2.简化操作
3.减少了编译次数并且减少了和数据库服务器的连接城市,提高了效率。
存储过程的语法为:
一、创建语法
CREATE PROCEDURE helloWord()
BEGIN
END
注意:
1.参数列表包含三部分
参数模式 参数名 参数类型
举例:
IN stuname VARCHAR(20)
参数模式:
IN : 该参数可以作为输入,也就是该参数需要调用方传入值
OUT:该产生可以作为输出,也就是该参数可以作为返回值
INOUT:改参数既可以输入也可以输出
1.创建in模式的存储过程
CREATE PROCEDURE myp2(IN `name` VARCHAR(20))
BEGIN
DECLARE res INT DEFAULT 0; #定义变量并初始化
SELECT COUNT(*) INTO res #赋值
FROM tab_identity
WHERE tab_identity.`NAME`=`name`;
SELECT IF(res>0,'成功','失败') 结果;
END
#调用存储过程
CALL myp2('张三丰');
2.创建out模式的存储过程
CREATE PROCEDURE myp4(IN `id` BIGINT(20),OUT boyName VARCHAR(20))
BEGIN
SELECT ide.`NAME` INTO boyName
FROM tab_identity ide
WHERE ide.`ID`=id;
END
#调用存储过程
CALL myp4(11,@bName);
SELECT @bName;
3.创建带inout模式的存储过程
#创建带inOut模式的存储过程
CREATE PROCEDURE myp6(INOUT `id` INT)
BEGIN
SET id=id*5;
END
#带有inout的存储过程调用需要先创建一个变量
SET @a=10;
CALL myp6(@a);
SELECT @a;
边栏推荐
- 【DBSCAN】DBSCAN实例
- Jedislock redis distributed lock implementation
- LoRa模块无线收发通信技术详解
- Some code fragments of a universal and confession wall system developed by PHP
- Empire CMS imitates DIY handmade website source code of craft activity /92kaifa imitates self-adaptive mobile phone version template of craft activity
- Address of my bookmark
- 微信小程序之点餐系统附源码
- 图片规则翻页
- 吴恩达机器学习课程-第七周
- Detailed explanation of Lora module wireless transceiver communication technology
猜你喜欢

Reprint: linearlayout+fragment to achieve the lower navigation bar effect

Introduction to steamvr

Tree topology networking structure of ZigBee module communication protocol

Detailed explanation of Lora module wireless transceiver communication technology

Internet of things security in the era of remote work

Differences between beanfactorypostprocessor and beanpostprocessor

Q1营收超华尔街预期,挚文集团的价值等待回归

Detail measurement of DC-DC and PDN with network analyzer

ugui图片墙

Technology cloud report: privacy computing under the wave of Web3.0
随机推荐
批量对数据添加噪声并生成新命名标注文件
BCGControlBar库专业版,完整记录的MFC扩展类
DENISON液压泵用什么液压油?有哪些要求
Introduction to ZigBee module wireless transmission star topology networking structure
Ugui picture wall
UGUI鼠标点击扩散UI效果
About CI framework batch export to compressed file
Habitable planet
安装MySQL ,出现由于找不到 MSVCR120.dll,无法继续执行代码解决方法”
Interview review - closure
rpc的正确打开方式|读懂Go原生net/rpc包
Mouse click coordinate transformation generation
Reprint: linearlayout+fragment to achieve the lower navigation bar effect
[Bert]: Calculation of last ave state when training tasks with similar Bert semantics
EMG线性光源发射器有哪些功能和特点呢?
【CV基础】颜色:RGB/HSV/Lab
LoRa模块无线收发通信技术详解
Cisp-pte XSS Foundation
[audio and video] Introduction to SEI
Some code fragments of a universal and confession wall system developed by PHP