|
李玉明-421 发表于 2011-12-20 14:23 ![]()
有关Oracle与DB2开发的问题也随时欢迎与我讨论。谢谢!
大神,麻烦帮我看下我的一个过程,新手第一次写,不太懂。谢谢!
drop procedure dbo.test_plsql ();
create procedure dbo.test_plsql ()
language sql
begin
declare SQLCODE int default 0;
declare v_1 varchar(100);
declare v_2 varchar(100);
DECLARE V_TOTAL_RECORDS_PRD INT;
DECLARE V_SUM_FIELD_PRD BIGINT;
declare v_sql1 varchar(1000);
declare v_sql2 varchar(1000);
declare cursor1 cursor for select tablename,field from dbo.imatrix_uat_honglei for update;
open cursor1;
cursorloop:
loop
fetch cursor1 into v_1,v_2;
IF SQLCODE=100 THEN LEAVE CURSORLOOP;
END IF;
set v_sql1='select count(*) into V_TOTAL_RECORDS_PRD from dbo.'||v_1;
set v_sql2='select sum('||v_2||') into V_SUM_FIELD_PRD from dbo.'||v_1;
execute immediate v_sql1;
execute immediate v_sql2;
update dbo.imatrix_uat_honglei set TOTAL_RECORDS_PRD=V_TOTAL_RECORDS_PRD,SUM_FIELD_PRD=V_SUM_FIELD_PRD where current of cursor1;
end loop;
close cursor1;
end;
call dbo.test_plsql ();
|
|