ORA-14551: 无法在查询中执行 DML 操作 解决方法
2012-04-13 12:31
627 查看
--创建测试表
create table fn_dml_test
(
ID NUMBER(20),
text VARCHAR2(200)
)
--创建函数
CREATE OR REPLACE FUNCTION fn_test(ID NUMBER) RETURN NUMBER
IS
/*
14551, 00000, "cannot perform a DML operation inside a query "
// *Cause: DML operation like insert, update, delete or select-for-update
// cannot be performed inside a query or under a PDML slave.
// *Action: Ensure that the offending DML operation is not performed or
// use an autonomous transaction to perform the DML operation within
// the query or PDML slave.
*/
pragma AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO fn_dml_test(id,text) values(ID,'success');
COMMIT;
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
INSERT INTO fn_dml_test(id,text) values(ID,'fail');
COMMIT;
RETURN 0;
END;
--查询验证
SELECT fn_test(1) from dual
create table fn_dml_test
(
ID NUMBER(20),
text VARCHAR2(200)
)
--创建函数
CREATE OR REPLACE FUNCTION fn_test(ID NUMBER) RETURN NUMBER
IS
/*
14551, 00000, "cannot perform a DML operation inside a query "
// *Cause: DML operation like insert, update, delete or select-for-update
// cannot be performed inside a query or under a PDML slave.
// *Action: Ensure that the offending DML operation is not performed or
// use an autonomous transaction to perform the DML operation within
// the query or PDML slave.
*/
pragma AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO fn_dml_test(id,text) values(ID,'success');
COMMIT;
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
INSERT INTO fn_dml_test(id,text) values(ID,'fail');
COMMIT;
RETURN 0;
END;
--查询验证
SELECT fn_test(1) from dual
相关文章推荐
- PL/SQL“ ORA-14551: 无法在查询中执行 DML 操作”解决
- PL/SQL“ ORA-14551: 无法在查询中执行 DML 操作”解决
- PL/SQL“ ORA-14551: 无法在查询中执行 DML 操作”解决
- 通过自治事务解决ORA-14551: 无法在查询中执行 DML 操作
- ORA-14551: 无法在查询中执行 DML 操作
- ORA-14551: 无法在查询中执行 DML 操作
- ORA-14551: 无法在查询中执行 DML 操作
- ORA-14551: 无法在查询中执行 DML 操作
- 如何绕过“ora-14551 无法在查询中执行DML操作”
- ORA-14551: 无法在查询中执行 DML 操作
- ORA-14551: 无法在查询中执行 DML 操作
- ORA-14551: 无法在查询中执行 DML 操作
- Oracle ORA-14551: 无法在查询中执行 DML 操作
- 执行SQL语句时出现问题操作必须使用一个可更新的查询错误的解决方法
- "执行SQL语句时出现问题操作必须使用一个可更新的查询"错误的解决方法
- C#中foreach出现“集合已修改 可能无法执行枚举操作”的解决方法
- sql 2000 无法执行查询,因为一些文件缺少或未注册"的解决方法
- 关于Hibernate执行查询后会引发update操作的解决方法
- ora-12154 tns 无法处理服务名(执行的程序途径不一致导致,枚举网络数种方法,大家还有其他解决办法?)
- ORA-14552: 在查询或 DML 中无法执行 DDL