当前位置:首页 > 学习笔记 > 数据库 > 数据库教程 存储过程

数据库教程 存储过程

刘广法2022年03月31日 19:15:47数据库5220
数据库教程 存储过程-第1张图片-刘广法IT博客

数据库教程 存储过程

关于数据库存储过程的相关描述:

1、优点:性能强

2、缺点:无法移植

3、mysql 存放在函数类型中,不调用不会执行(存储过程需要单独调用)

参数类型:

in:传入参数

out:传出参数

intout:既可以传入又可以传出

-- 存储过程,不需要返回值

create procedure p_tese(in n int)
begin
    -- 定义一个变量
    declare a int default 1;
    declare s int default 0;
    -- 循环
    while a <= n do
        set s = s + a;
        set s = s + 1;
    end while;
    
    update t_student set height = s where id =500;
end

调用函数:call p_test(100)


实例二:

create procedure p_get_seudent_count(classid int)
begin
    
    declare end_loop int default 1;
    declare v_classid int;
    declare v_height int;
    declare v_count int default 0;
    
    -- 定义游戏
    declare cur cursor for select class_id,height from t_student where class_id = clasaid;
    
    -- 定义游标 到尾端,赋值end_loop为0
    declare continue handler for not found set end_loop = 0;
    
    -- 打开游标
    open cur;
    
    while end_loop = 1 do
        fetch cur into v_classid,v_height;
        
        if v_height > 170 then
            set v_count = v_count +1;
        end if;
    end while;
    
    update t_class set student_cut = v_count where id =classidl
    
    close cur;
end


本文作者:刘广法,转载注明出处。

扫描二维码推送至手机访问。

版权声明:本文由刘广法博客发布,如需转载请注明出处。

本文链接:https://liuguangfa.com/database/55.html

分享给朋友:

“数据库教程 存储过程” 的相关文章

SQL是什么?SQL能做什么?

SQL是什么?SQL能做什么?

SQL是什么?SQL (Structured Query Language:结构化查询语言) 是用于管理关系数据库管理系统(RDBMS)。 SQL 的范围包括数据插入、查询、更新和删除,数据库模式创建和修改,以及数据访问控制。SQL语言主要用于存取数据、查询数据、更新数据和管理关系数据库系...

数据库教程 jdbc

java 和 数据库 连接技术odbc:淘汰10年了。只能用在windows系统上关于jdbc 的相关描述:关于jdbc的实操七步:package com.liuguangfa.jdbc; import java.sql.Connection; import j...

数据库练习 数据库查询练习 ***

冰人集团系统数据库设计1. 使用MySQL 8.x版本数据库,使用Navicat作为数据库客户端管理图形界面工具。2. 创建名为“iceman2018”的数据库。字符集使用utf8 -- UTF-8 Unicode,排序规则使用utf8_general_ci。3. 创建“部门”表,表名为t_depa...

数据库教程 设计模式(单例模式、代理模式、工厂模式)

Java中常用的设计模式:概况:1、单例模式饱汉式饿汉式内部类实现2、工厂模式3、代理模式静态代理动态代理num1:单例模式1.1 饱汉式public class Singleton { private static final Stu...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。