mysql存储过程

存储过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `p09825`(in startpos int,in pagesize int)
begin
declare id int;
set id=startpos;
while id<pagesize do
update ba_topic set reply_count=(select count(*) from ba_topic_reply where ba_topic_id=id and status=1) where ba_topic_id=id;
set id=id+1;
end while;
end;


mysql> delimiter //

mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM t;
-> END;
-> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;

mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)

你可能感兴趣的:(mysql)