orcal 存储过程 更新数据时,违反唯一约束怎么在存储过程添加异常处理将这条记录删除,然后在继续执行!
CREATEORREPLACEPROCEDUREHB_ID(OPIDINVARCHAR2,OVIDINnumber,NPIDINVARCHAR2,NVIDINnumber...
CREATE OR REPLACE PROCEDURE HB_ID(OPID IN VARCHAR2,OVID IN number,NPID IN VARCHAR2,NVID IN number)IS
V_CURSQL VARCHAR2(1000);
V_SQLCURSOR SYS_REFCURSOR;
TBL_NAME VARCHAR2(100);
PID_COL VARCHAR2(100);
VID_COL VARCHAR2(100);
UPDATESQL VARCHAR2(1000);
cnt integer;
BEGIN
V_CURSQL :='SELECT T.TBL_NAME,T.PID_COL,T.VID_COL FROM MNR_TY_CFG_TBL T';
cnt :=1;
OPEN V_SQLCURSOR FOR V_CURSQL;
LOOP
FETCH V_SQLCURSOR
INTO TBL_NAME,
PID_COL,
VID_COL;
dbms_output.put_line(to_char(SYSDATE,'hh24:mi:ss'));
UPDATESQL :='UPDATE '||TBL_NAME||' SET '||PID_COL||'='''||NPID||''' , '||VID_COL||'='||NVID||'
WHERE '||PID_COL||'='''||OPID||''' AND '||VID_COL||'='||OVID||'';
EXECUTE IMMEDIATE UPDATESQL;
COMMIT;
dbms_output.put_line(to_char(SYSDATE,'hh24:mi:ss'));
cnt :=cnt+1;
EXIT WHEN V_SQLCURSOR%NOTFOUND;
END LOOP;
CLOSE V_SQLCURSOR;
END HB_ID; 展开
V_CURSQL VARCHAR2(1000);
V_SQLCURSOR SYS_REFCURSOR;
TBL_NAME VARCHAR2(100);
PID_COL VARCHAR2(100);
VID_COL VARCHAR2(100);
UPDATESQL VARCHAR2(1000);
cnt integer;
BEGIN
V_CURSQL :='SELECT T.TBL_NAME,T.PID_COL,T.VID_COL FROM MNR_TY_CFG_TBL T';
cnt :=1;
OPEN V_SQLCURSOR FOR V_CURSQL;
LOOP
FETCH V_SQLCURSOR
INTO TBL_NAME,
PID_COL,
VID_COL;
dbms_output.put_line(to_char(SYSDATE,'hh24:mi:ss'));
UPDATESQL :='UPDATE '||TBL_NAME||' SET '||PID_COL||'='''||NPID||''' , '||VID_COL||'='||NVID||'
WHERE '||PID_COL||'='''||OPID||''' AND '||VID_COL||'='||OVID||'';
EXECUTE IMMEDIATE UPDATESQL;
COMMIT;
dbms_output.put_line(to_char(SYSDATE,'hh24:mi:ss'));
cnt :=cnt+1;
EXIT WHEN V_SQLCURSOR%NOTFOUND;
END LOOP;
CLOSE V_SQLCURSOR;
END HB_ID; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询