1

使用存储的函数调用 NVL 和 NVL2 函数。即使不从该函数返回值,也会调用函数。请看下面的例子。

create or replace
 function f1
      return varchar2
     is
    begin
        ---set serveroutput on
         dbms_output.put_line('Call to F1');
         return 1;
  end;

set serveroutput on

select  NVL2(null,f1,100)   from  dual


NVL2(NULL,F1,100)                                                              
--------------------------------------------------------------------------------
100                                                                             
Call to F1

select nvl('x',f1) from dual

NVL('X',F1)                                                                    
--------------------------------------------------------------------------------
x                                                                               
Call to F1

因此,虽然 NVL 和 NVL2 函数返回了正确的值,但函数也被调用。

此逻辑在许多地方使用,并导致对函数的额外调用导致性能下降。任何帮助表示赞赏。

Oracle 版本是 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

4

0 回答 0