Oracle 12c – WITH FUNCTION


17.06.2014
by Kamil Stawiarski

In Oracle 12c there is a possibility to define a PL/SQL function inside the "WITH" clause, which can reduce the context switching overhead.

Short example:

SQL> create or replace function F_DUMMY(x number) return number as
  2  begin
  3     return x+100;
  4  end;
  5  /

Function created.

SQL> set timing on           
SQL> select sum(F_DUMMY(amount_sold))
  2  from sales_big;

SUM(F_DUMMY(AMOUNT_SOLD))
------------------------
              3041442099

Elapsed: 00:01:50.44
SQL> /

SUM(F_DUMMY(AMOUNT_SOLD))
------------------------
              3041442099

Elapsed: 00:01:37.99

SQL> ;
  1  with function F_DUMMY2(x number) return number as
  2    begin
  3       return x+100;
  4    end;
  5  select sum(F_DUMMY2(amount_sold))
  6* from sales_big
SQL> /

SUM(DUPSKO2(AMOUNT_SOLD))
-------------------------
               3041442099

Elapsed: 00:00:07.03

SQL> /

SUM(DUPSKO2(AMOUNT_SOLD))
-------------------------
               3041442099

Elapsed: 00:00:07.22

Contact us

Database Whisperers sp. z o. o. sp. k.
al. Jerozolimskie 200, 3rd floor, room 342
02-486 Warszawa
NIP: 5272744987
REGON:362524978
+48 508 943 051
+48 661 966 009
info@ora-600.pl

Newsletter Sign up to be updated