Oracle觸發(fā)器表發(fā)生了變化 觸發(fā)器不能讀它的解決方法(必看)
出現(xiàn)原因,是因為在更新的的表和讀取的表是同一個表。
CREATE or replace TRIGGER T_userupdateT BEFORE update ON T_user REFERENCING OLD AS old NEW AS N_ROW FOR EACH ROW
DECLARE U_xtfidemp1 varchar(36);
u_xtempcode1 varchar(20);
u_xtempcodeCount int:=0;
U_xtfidempCount int:=0;
u_id1 int:=0;
BEGIN
U_xtfidemp1:=:N_ROW.U_xtfidemp;
u_xtempcode1:=:N_ROW.u_xtempcode;
u_id1:=:N_ROW.u_id;
select count(u_xtempcode) into u_xtempcodeCount from eas.T_user where u_xtempcode is not null and u_xtempcode=u_xtempcode1 and u_id<>u_id1;
select count(U_xtfidemp) into U_xtfidempCount from eas.T_user where U_xtfidemp is not null and U_xtfidemp=U_xtfidemp1 and u_id<>u_id1;
IF u_xtempcodeCount>0 or U_xtfidempCount>0 THEN
RAISE_APPLICATION_ERROR(-20001, 'eas.T_user u_xtempcode,U_xtfidemp,U_GZCode更新數(shù)據(jù)時有錯誤,有重復(fù)');
END IF;
end;
出現(xiàn)錯誤時,是因為觸發(fā)器在T_userupdateT在T_user上,觸發(fā)器內(nèi)部有讀取了T_user所以有錯誤。
修改如下
CREATE or replace TRIGGER T_userupdateT BEFORE update ON T_user REFERENCING OLD AS old NEW AS N_ROW FOR EACH ROW
DECLARE U_xtfidemp1 varchar(36);
u_xtempcode1 varchar(20);
u_xtempcodeCount int:=0;
U_xtfidempCount int:=0;
u_id1 int:=0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
U_xtfidemp1:=:N_ROW.U_xtfidemp;
u_xtempcode1:=:N_ROW.u_xtempcode;
u_id1:=:N_ROW.u_id;
select count(u_xtempcode) into u_xtempcodeCount from eas.T_user where u_xtempcode is not null and u_xtempcode=u_xtempcode1 and u_id<>u_id1;
select count(U_xtfidemp) into U_xtfidempCount from eas.T_user where U_xtfidemp is not null and U_xtfidemp=U_xtfidemp1 and u_id<>u_id1;
IF u_xtempcodeCount>0 or U_xtfidempCount>0 THEN
RAISE_APPLICATION_ERROR(-20001, 'eas.T_user u_xtempcode,U_xtfidemp,U_GZCode更新數(shù)據(jù)時有錯誤,有重復(fù)');
END IF;
COMMIT;
end;
多了PRAGMA AUTONOMOUS_TRANSACTION;COMMIT;兩句
以上這篇Oracle觸發(fā)器表發(fā)生了變化 觸發(fā)器不能讀它的解決方法(必看)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解azure 云上準(zhǔn)備oracle11g的vnc安裝環(huán)境
本篇文章主要介紹了詳解azure 云上準(zhǔn)備oracle11g的vnc安裝環(huán)境,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03
Oracle賬戶被鎖錯誤:the?account?is?locked解決方法
the?account?is?locked意思是賬戶被鎖定了,這種情況需要大家去解鎖,這篇文章主要給大家介紹了關(guān)于Oracle賬戶被鎖錯誤:the?account?is?locked的解決方法,需要的朋友可以參考下2023-12-12
Oracle用decode函數(shù)或CASE-WHEN實現(xiàn)自定義排序
這篇文章主要介紹了Oracle用decode函數(shù)或CASE-WHEN實現(xiàn)自定義排序功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
oracle數(shù)據(jù)庫關(guān)于索引建立及使用的詳細(xì)介紹
這篇文章主要介紹了oracle數(shù)據(jù)庫關(guān)于索引建立及使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
oracle11g客戶端連接12c服務(wù)器ORA-01017錯誤問題解決
這篇文章主要介紹了oracle11g客戶端連接12c服務(wù)器ORA-01017錯誤,本文給大家分享完美解決方法,對oracle 12c錯誤ORA-01017問題解決方法感興趣的朋友跟隨小編一起看看吧2023-06-06
ORACLE 數(shù)據(jù)庫RMAN備份恢復(fù)
還原不同位置的數(shù)據(jù)庫2009-04-04
講解Oracle數(shù)據(jù)庫中結(jié)束死鎖進(jìn)程的一般方法
這篇文章主要介紹了Oracle數(shù)據(jù)庫中結(jié)束死鎖進(jìn)程的一般方法,包括查詢死鎖以及避免死鎖的建議等內(nèi)容,需要的朋友可以參考下2016-01-01
Windows Server 2012 安裝oracle11g(圖文教程)
這篇文章主要介紹了Windows Server 2012 安裝oracle11g(圖文教程),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12

