CREATE PROCEDURE Sys_Init_tblaccountsuser_sortid () P1: BEGIN
declare not_found condition for sqlstate '';
DECLARE V_RK_ID INTEGER DEFAULT 0;
DECLARE V_ID INTEGER DEFAULT 0;
DECLARE V_AT_END INT DEFAULT 0; DECLARE CUR1 CURSOR WITH RETURN TO CLIENT FOR
select rk,id from (select rank() over(partition by ouid order by id asc) rk,t.* from tracing.tblaccountsuser t); declare continue handler for not_found set V_AT_END=1;
-- Cursor left open for client application
OPEN CUR1;
ins_loop:
LOOP
FETCH CUR1 INTO V_RK_ID,V_ID;
IF V_AT_END <>0 THEN
LEAVE ins_loop;
END IF; update tblaccountsuser set SORTID = V_RK_ID where id = V_ID ;
END LOOP;
CLOSE CUR1;
END P1