DB2使用存儲過程插入數據 要求:插入一張表(TESTMV)中三個字段(ID, GROUPID【組id】, USERID【用戶id】),為了產生多個組,每個組多個人的數據,進行統計每個組多少人數據用 代碼如下:
[html] delete testmv; create procdedure insertdb() language SQL begin declare v_num int; declare v_num1 int; declare v_num2 varchar(12); set v_num=0; set v_num1=1; loop1: LOOP if(v_num<100) then set v_num = v_num +1; set v_num1=1; loop2: LOOP if(v_num1<=100) then insert into testmv(ID, GROUPID, USERID) VALUES('id'||v_num||v_num1, 'groupid'||v_num, 'userid'||v_num||v_num1); set v_num1=v_num1+1; else leave loop2; end if; end loop loop2; else leave loop1; end if; end loop loop1; end; call insertdb(); drop procedure insertdb();