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

    一、无参存储过程

    delimiter //
    create procedure p1() 
    BEGIN
        select * from db7.teacher;  # 写sql语句
    END //
    delimiter ;
    
    # MySQL中调用
    call p1();
    
    #Python中调用
    cursor.callproc('p1')  # 执行sql语句
    print(cursor.fetchall()) # 打印结果

    二、有参存储过程

    delimiter //
    create procedure p2(in n1 int,in n2 int,out res int)
    BEGIN
        select * from db7.teacher where tid >n1 and tid < n2;
        set res = 1;
    END //
    delimiter ;
    
    
    # MySQL中调用
    set @x=0
    call p2(2,4,@x);
    select @x;  # 查看返回值

    # Python中调用
    cursor.callproc('p2',(2,4,0)) #参数代表 @_p2_0=2,@_p2_1=4,@_p2_2=0
    print(cursor.fetchall()) # 查看结果
    cursor.execute(select @_p2_2) #取返回值
    print(cursor.fetchone()) #查看返回值
  • 相关阅读:
    (31)对象的克隆
    (30)批处理文件.bat
    06.v-on的修饰符
    06.v-on参数问题
    06.2修饰符补充
    06.1v-on基础+-.
    03.data数据对象
    02.el挂载点
    02.5v-pre指令
    02.4v-text指令
  • 原文地址:https://www.cnblogs.com/nanjo4373977/p/12329331.html
Copyright © 2011-2022 走看看