CREATE OR REPLACE PROCEDURE "fun" is
--定义游标 获取主键以及相关
cursor results is SELECT
t.c1,
t.c2,
t.c3
FROM table t where t.id='xx';
--将查询结果转为行数据
nrm_row results%ROWTYPE;
--全局变量
var1 NVARCHAR2(30);
var2 DATE;
var3 NUMBER(16,2);
BEGIN
--遍历数据
FOR nrm_row IN results LOOP
var1 := nrm_row.c1;
var2 := sysdate;
var3 := nrm_row.c3;
begin
doing something....
--COMMIT;
exception
WHEN OTHERS THEN
--SUBSTR(SQLERRM, 1, 1000)
DBMS_OUTPUT.PUT_LINE('xxx处理错误,错误代码:'||SQLCODE||'错误信息:'||SQLERRM);
end;
END LOOP;
END;