Note: The value of the statement must be a parameter with the @ symbol, not its own local variables, a @ called user variables, two @ is called a global variable. User variables: The current user's "global variables", the existence of the user state exists, the user exits when it disappears.
Initial version
if exists p1 () create procedure P1 () Begin int ; Set One ; set @p1 = i1; from ' SELECT * from info where nid >? ' ; using @p1; -- performing pretreatment deallocate prepare prod ; -- Delete preprocessing end \delimiter;
Advanced version
delimiter \drop procedureifexists p1 () create procedure P1 (inchstrSQL varchar ( -), ----Dynamic Get ParametersinchNidint----dynamic get parameters) beginSet@p1 =nid; Set@sql1 =strSQL; Prepare prod from@sql1; Execute PRODusing@p1; --perform pretreatment deallocate prepare prod; --Delete preprocessing end \delimiter; #调用call P1 ("SELECT * from info where nid >?",1)
Python calls Pymysql
row = Cursor.callproc ('p1', ("select * from info where nid >? ",6= Cursor.fetchall ()
MySQL--Dynamic fetch result set (emphasis)