zoukankan      html  css  js  c++  java
  • 存储过程

    存储过程
        存储过程就是在sql里面定义条件判断各种函数执行的一系列操作。
     
    定义存储过程:
        create  procedure proc_p1()
        begin
            select * from     man;
        end
     
    调用存储过程:
        call proc_p1()
     
    删除存储过程:
    drop procedure proc_p1; / dro procedure if exists proc_p1;
     
    定义带参数的存储过程:
    set @o = 5;
    create procedure proc_p1(
    in i1 int,//in i1 int 定义参数
    out i2 int,  //out i2 int定义输出参数
    inout ii int) //
    begin
        declare d1 int;  declare 定义变量关键字
        declare d2 int default 3; 定义变量并制定默认值
        set d1 =i1+d2;  设置变量
        select * from man_to_women where nid > d1;
     
        if i1 =1 then
            set i2 = 100+d2;
        elseif i1 =2 then
            ...
        else
            set i2 = 1000 +d2;
        end if; 
    end
     
    delimiter xx  指定终端的结束符
    call proc_p1(1,@o,@u); 这里的@u是吧变量当作引用传递进去。
    select @u;
     
    想要获取存储过程调用的参数的值,可以这样:
    ffect_row = cursor.execute("select @_proc_p1_0,@_proc_p1_1,@_proc_p1_2")
    result = cursor.fetchone();
     
    我们也可以在存储过程中将select获取的结果不返回给用户,而是在内部再一次处理:
    begin
        declare d2 int 0;
        select man into d2 from man where man_id=d2;
        select name from man where nid = d2;
    end
  • 相关阅读:
    synergy一个鼠标键盘控制多台电脑
    matlab 画图参考小程序
    基于centos7的真实机环境下安装 vmware workstastion
    mapreduce运行原理及YARN
    mybatis_resultMap(2)
    (第6天)mybatis_resultMap(1)
    mybatis动态SQL--传入参数为集合,数组类型
    mybatis动态SQL--Trim --Where
    mybatis动态SQL--if--choose
    (第5天)mybatis接口方法入参类型
  • 原文地址:https://www.cnblogs.com/dontgiveup/p/9373330.html
Copyright © 2011-2022 走看看