ORA-04092: cannot COMMIT in a trigger錯誤的解決
今天處理一個程式報錯的問題,發現開發人員在trigger使用了rollback, commit 等控制語句,報錯資訊: ORA-04092 .
ORA-04092 cannot string in a trigger
Cause: A trigger attempted to commit or roll back.
Action: Rewrite the trigger so it does not commit or roll back
------------------------------------------------------------
CREATE OR REPLACE TRIGGER ASN.DBS_INBOUND_TAIL
AFTER UPDATE
ON ASN.DBS_INBOUND_TAIL
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
tmpVar2 NUMBER;
BEGIN
tmpVar := 0;
tmpVar2 := 0;
SELECT COUNT(*) INTO tmpVar FROM DBS_INBOUND_DTL
WHERE SHIPPING_NO=:NEW.SHIPPING_NO;
SELECT SHIPPING_QTY INTO tmpVar2 FROM DBS_INBOUND_HDR
WHERE SHIPPING_NO=:NEW.SHIPPING_NO;
IF tmpVar <> tmpVar2 THEN
ROLLBACK;
END IF;
END ;
/
---------------------------------------------------------------
網上實驗轉帖:
---------------------------------------------------------------
SQL> create table t1
2 (a int);
Table created.
SQL> desc students4
Name Null? Type
----------------------------------------- -------- ---------------
NAME VARCHAR2(20)
DEPT_ID NUMBER
現象一:在觸發器中使用DDL語句。
Step01:建立觸發器tri_pt,觸發器的主體將刪除表t1。
SQL> create or replace trigger tri_pt
2 after delete on students4
3 for each row
4 DECLARE
5 v_dept_id int;
6 begin
7 execute immediate 'drop table t1';--DDL操作
8 end;
9 /
Trigger created.
〖小貼士(Tip) 〗
DDL語句隱含commit。
Step02:刪除表students4的資料,這個表將點燃觸發器tri_pt。
SQL> delete from students4 where name='MARY';
delete from students4 where name='MARY'
*
ERROR at line 1:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "TEST.TRI_PT", line 4
ORA-04088: error during execution of trigger 'TEST.TRI_PT'
現象二:
Step01:建立觸發器tri_pt,觸發器的主體中使用了commit語句。
SQL> create or replace trigger tri_pt
2 after delete on students4
3 DECLARE
4 v_dept_id int;
5 begin
6 commit;
7 end;
8 /
Trigger created.
Step02:刪除表students4的資料,將點燃觸發器tri_pt。
SQL> delete from students4 where name='MARY';
delete from students4 where name='MARY'
*
ERROR at line 1:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "TEST.TRI_PT", line 4
ORA-04088: error during execution of trigger 'TEST.TRI_PT'
〖原理(Cause) 〗
DML(delete/update/insert)觸發器中不能使用DDL(CREATE,DROP,ALTER)語句,也不能使用事務控制語句(ROLLBACK, COMMIT,SAVEPOINT)。特別注意的是,在觸發器的主體中引用的函式(function)/過程(procedure)中也不能有事物控制語句。
〖小貼士(Tip) 〗
系統級觸發器(System Triggers)中可以使用DDL語句。
〖方法(Action) 〗
去掉事務控制語句
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-433098/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Ubuntu Cannot allocate memory 錯誤解決方案Ubuntu
- 【git】Git commit時提示錯誤時 解決辦法GitMIT
- SyntaxError: Non-ASCII character 與 Cannot decode using encoding "ascii" 錯誤解決ErrorASCIIEncoding
- 132 SVN提交報錯"Commit blocked by pre-commit hook"的解決辦法MITBloCHook
- mongodb錯誤解決辦法-bash: ./mongod: cannot execute binary file: Exec format errorMongoDBORMError
- Ocelot錯誤解決
- Go 自定義日期時間格式解析解決方案 - 解決 `parsing time xx as xx: cannot parse xx as xx` 錯誤Go
- undefined reference to錯誤的解決方法Undefined
- Cocopods的升級錯誤解決
- ORA-12005 錯誤的解決
- SAXParseException的錯誤解決之二Exception
- 解決 Python UnicodeEncodeError 錯誤PythonUnicodeError
- 使用pillow開啟TIFF檔案報tempfile.tif: Cannot read TIFF header錯誤的解決方案Header
- 解決String cannot be cast to java.util.List報錯ASTJava
- dbfread報錯ValueError錯誤解決方法Error
- 解決 ngrok 的 Domain 錯誤問題AI
- Qt報Multiple definition錯誤的解決QT
- 解決MySQL server has gone away錯誤的解決方案MySqlServerGo
- eclipse中:The type java.lang.object cannot be resolved錯誤(jdk配置錯誤)EclipseJavaObjectJDK
- PbootCMS 404 錯誤解決方法boot
- Linux下錯誤解決方案Linux
- latex 錯誤以及解決方案
- MogDB 安裝解壓錯誤:cannot run bzip2: No such file or directory
- HTTP 錯誤 500.19- Internal Server Error 錯誤解決方法HTTPServerError
- steam磁碟寫入錯誤怎麼解決 steam磁碟寫入錯誤解決方法大全
- 解決 eslint 的 Parsing error: Unexpected token 錯誤EsLintError
- Mac上搭建chromedriver的錯誤解決方法MacChrome
- standby新增檔案錯誤的解決方法
- nginx出現403錯誤的解決方法Nginx
- 一個 ExpressionChangedAfterItHasBeenCheckedError 錯誤的解決過程ExpressError
- MYSQL中 TYPE=MyISAM 錯誤的解決方法MySql
- [譯] 避免那些可惡的 "cannot read property of undefined" 錯誤Undefined
- ORA-28000錯誤解決方案
- dedecms提示500錯誤解決方法
- PHP curl error 60 錯誤解決PHPError
- linux解決“XXX is not in the sudoers file”錯誤Linux
- 解決java.lang.NoSuchMethodError錯誤JavaError
- HTTP代理錯誤怎麼解決?HTTP
- TCP網路除錯助手提示錯誤:“1035:未知錯誤” 解決方案TCP除錯