gpt4 book ai didi

oracle - (PLSQL) 测试 Oracle 更新触发器中更改值的最简单表达式是什么?

转载 作者:行者123 更新时间:2023-12-01 11:07:39 26 4
gpt4 key购买 nike

这是一个 bool 表达式,可以解决这个问题:

nvl(:new.location != :old.location, (:new.location is null) != (:old.location is null))

但我想有一个更简单的表达方式。有什么想法吗?

最佳答案

这些较短的方法都有几个缺点。它们很慢,不直观,可能有问题(尽可能避免使用魔法值),并且比 AND/OR/IS NULL/IS NOT NULL 等正常条件更具专有性。

NVL、DECODE、COALESCE 等,可能比您想象的更昂贵。

我在几个不同的上下文中看到过很多次,这是一个简单的例子:

--Shorter method: Takes about 0.45 seconds
declare
j number;
begin
for i in 1 .. 1000000 loop
j := i;
if nvl(i <> j, (i is null) <> (j is null)) then
null;
end if;
end loop;
end;
/

--Normal method: Takes about 0.25 seconds
declare
j number;
begin
for i in 1 .. 1000000 loop
j := i;
if i <> j or (i is null and j is not null) or (i is not null and j is null) then
null;
end if;
end loop;
end;
/

我建议您多花点时间以合乎逻辑的方式输入它。您的代码将看起来更好,运行速度更快。

关于oracle - (PLSQL) 测试 Oracle 更新触发器中更改值的最简单表达式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3678436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com