示例
DELIMITER //
CREATE PROCEDURE proc (IN num INT)
BEGIN
SELECT * FROM v9_qd_account limit num;
END //
DELIMITER ;
执行:
SET @p_in=5;
CALL proc(@p_in);
或者
CALL proc(5);
循环
DECLARE num int default 5;
SET num = 1;
SET num = num + 1;
DELIMITER // CREATE PROCEDURE proc(IN sname VARCHAR(20),IN pwd VARCHAR(5),IN qd INT,IN start INT,IN end INT) begin DECLARE var INT; DECLARE myname VARCHAR(30); SET var=start; while var<end do SET myname = CONCAT(sname,LPAD(var,3,'0')); insert into v9_qd_account (storename,password,qudao,regdate) value(myname,md5(pwd),qd,UNIX_TIMESTAMP()); SET var=var+1; end while; end // DELIMITER ;
调用
CALL proc('test','123456',1,1,21);
查看
SHOW PROCEDURE STATUS LIKE 'C%' G; 查看以字母C开头的存储过程
SHOW CREATE PROCEDURE proc G; 查看状态和创建语句
information_schema.Routines 中查看
删除
DROP PROCEDURE IF EXISTS proc;
DROP FUNCTION mytest;
点拨
如果参数中有中文可以这样
CREATE PROCEDURE useInfo(IN u_name VARCHAR(50) character set gbk,OUT u_age INT) ......