存储过程
1.创建过程


delimiter // create procedure p1() BEGIN select * from t1; END// delimiter; --执行存储过程 call.p1()
存储过程,可以接收参数,参数有三类:
in 仅用于传入参数用
out 仅用于返回值用
inout 既可以传入又可以当做返回值


---创建存储过程 delimite \\ create proceduer p1() in i1 int, in i2 int, out i3 int , inout r1 int ) BEGIN declare 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;


-- 无参数 call proc_name() -- 有参数,全in call proc_name(1,2) -- 有参数,有in,out,inout set @t1=0; set @t2=3; call proc_name(1,2,@t1,@t2)


import pymysql conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='t1') cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 执行存储过程 cursor.callproc('p1', args=(1, 22, 3, 4)) # 获取执行完存储的参数 cursor.execute("select @_p1_0,@_p1_1,@_p1_2,@_p1_3") result = cursor.fetchall() cursor.close() conn.close() print(result)