在异常处理方面需要帮助。如果我运行这个 UPDATE 脚本一旦它工作,但是当我运行相同的脚本两次或多次时,我会收到以下错误“1 row updated.commited”,但它不正常。我想收到异常。“注意:表格已经更新”
UPDATE FBTB_TXNLOG
SET txnstageid = '-1',
LOCKED = 'N',
where xrefid = 'FJB1229000056689';
commit;
试试这个解决方案:
SET SERVEROUTPUT ON -- need for dbms_output.put_line()
declare
cnt int;
begin
-- if data exists
SELECT count(1)
INTO cnt
FROM FBTB_TXNLOG
WHERE txnstageid = '-1'
and LOCKED = 'N'
and xrefid = 'FJB1229000056689';
if (cnt > 0 )
then
-- exists: display message
dbms_output.put_line('Table is already updated');
else
-- let's edit
UPDATE FBTB_TXNLOG
SET txnstageid = '-1',
LOCKED = 'N',
where xrefid = 'FJB1229000056689';
commit;
end if;
end;
/