首页 > 其他 > 详细

存储过程

时间:2020-02-19 00:53:52      阅读:55      评论:0      收藏:0      [点我收藏+]

一、无参存储过程

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;  # 查看返回值

 

存储过程

原文:https://www.cnblogs.com/nanjo4373977/p/12329331.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!