zoukankan      html  css  js  c++  java
  • 数据库高级应用之存储过程

    存储过程作用:
    存储在数据库服务端供客户端使用的调用执行的SQL语句就是存储过程

    格式:
    sql 语句:
        create procedure p_student
            @dept char(20)
            as
                select sname,cname,grade
                    from student s join score sc on s.sno = sc.sno join course c on c.cno = sc.cno
                    where sdept = @dept

    MySQL语句:
    create procedure pr_add
    (
       a int,
       b int
    )
    begin
       declare c int;
       if a is null then
          set a = 0;
       end if;
       if b is null then
          set b = 0;
       end if;
       set c = a + b;
       select c as sum;
       
    end;


    执行存储过程:

    单个或者知道序列顺序的使用:
    Exec p_student '计算机系'

    多个参数的使用:
    Exec p_student @sdept = '计算机系',@cname = '数学'

  • 相关阅读:
    The Triangle_DP
    LITTLE SHOP OF FLOWERS_DP
    K Best(最大化平均数)_二分搜索
    Number Game_状态压缩
    Stockbroker Grapevine_Floyd
    A very hard Aoshu problem
    AOE 网络
    AOV网
    最小生成树
    [POJ] 1562 Oil Deposits (DFS)
  • 原文地址:https://www.cnblogs.com/Stakes-ds/p/8454469.html
Copyright © 2011-2022 走看看