解决“无法在查询中执行DML操作". [英] Solve "cannot perform a DML operation inside a query "
本文介绍了解决“无法在查询中执行DML操作".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的pl SQL脚本将金额c从帐户a转移到b.为什么不允许更新函数中的表/如何对其进行修复?
The pl SQL script below transfers the amount c of money from account a to b. Why isn't allowed to update the table in the function / how can it be fixed?
create or replace function ueberweisung (a varchar2, b varchar2,c number)
RETURN varchar2 IS
k1 number; -- Variablendeklaration
k2 number;
BEGIN
SELECT saldo into k1
FROM konto
WHERE konto_nr=a;
SELECT saldo into k2
FROM konto
WHERE konto_nr=b;
k1:=k1-c;
k2:=k2+c;
update konto
set saldo = case
when konto_nr=a then k1
when konto_nr=b then k2
end;
commit;
RETURN (c ||'Eur überwiesen von Konto ' || a || 'a uf Konto ' || b);
END ueberweisung;
推荐答案
它是
为了防止令人讨厌的副作用和可预测的行为,Oracle服务器使您在SQL中的存储函数无法采取以下任何操作:存储函数可能无法修改数据库表 .
使用 PL/SQL过程代替 PL/SQL具有两种类型的子程序,即过程和函数.通常,您使用过程执行操作,并使用函数来计算值. 这篇关于解决“无法在查询中执行DML操作".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文