数据库创建存储过程

创建存储过程的原因:一般在数据库中SQL编辑器只能写sql语句,创建存储过程后可在对象编辑器中加入除了sql语句之外的语句(例如:if,else语句)。创建存储过程类似于python中创建函数,可传参。

一.在Mysql-front创建过程(创建过程生成的代码在对象编辑器,执行过程在SQL编辑器)

二.在终端输入命令创建存储过程

1.无参

创建过程
delimiter // create procedure p1() BEGIN select * from t1; END// delimiter ;

终端执行过程 call p1()
python执行过程
cursor.callproc('p1')
result=cursor.fetchall()
print(result)

2.含参

创建过程
delimiter \\ create procedure p1(
in i1 int, #只能传进参数,没有返回值 in i2 int, inout i3 int, #可传进参数,有返回值 out r1 int #传进的参数无用,out相当于return ) BEGIN DECLARE temp1 int; #声明temp1是int类型 DECLARE temp2 int default 0; set temp1 = 1; set r1 = i1 + i2 + temp1 + temp2; set i3 = i3 + 100; end\\ delimiter ;

终端执行过程
set @t1 =4;
set @t2 = 0;
CALL p1 (1, 2 ,@t1, @t2);
SELECT @t1,@t2;

python执行过程:
cursor.callproc('p1',args=(1,22,3,4))
cursor.execute('select @_p1_0,@_p1_1,@_p1_2,@_p1_3') #按照参数依次取

 

posted @ 2017-12-18 22:35  MISF  阅读(2861)  评论(0编辑  收藏  举报
     JS过度和变形效果演示   
  
    html5.png