Mysqlはカーソルを使用してクエリー結果セットを巡回し、操作します.
1608 ワード
/* A S_S ( ), S_S */
/* , , 。*/
drop procedure if exists proc_tmp;
create procedure proc_tmp()
BEGIN
/* :
DECLARE
done
INT
DEFAULT
FALSE
;
*/
declare done int default 0; /* */
declare hostId bigint; /* S_S ( S_S bigint )*/
/* */
declare idCur cursor for select id from wkp_order where source = '1';
/* done */
declare continue handler for not FOUND set done = 1; /*done = true; */
open idCur; /* */
/* */
REPEAT
/* fetch ,fetch cur/* idCur*/
/*into rowId, rowName; rowId rowName declare, declare cur select , rowId、rowName */
fetch idCur into hostId; /* , fetch ( S_S )*/
if not done THEN /* 0,MySQL true*/
INSERT into wkp_trade_log ( user_id, change_direction , type, order_no, amount, create_time , account_before, account_after) select seller_user_id ,'in','pay',order_no, (total_amount * 0.99) total_amount , create_time, 0 , 0 from wkp_order where source = '1' and id = hostId;
INSERT into wkp_trade_log ( user_id, change_direction , type, order_no, amount, create_time , account_before, account_after) select seller_user_id user_id ,'out','payFee',order_no, (total_amount * 0.01) total_amount , create_time, 0 , 0 from wkp_order where source = '1' and id = hostId;
end if;
until done end repeat;
close idCur; /* */
END
/* */
call proc_tmp();
drop procedure proc_tmp; /* */