oracle - pl/sql function called how many times? -
assume have following update:
update table set col1 = func(col2) col1<>func(col2)
the func function evaluated 2 times every row, or once every row?
thanks,
this kind of situation experimentation useful (this conducted on 10g). using following query, can tell normal functions, using same parameters (in case, none) executed each time called:
select dbms_random.value() all_tables
this because oracle assumes function not return same value consistently unless tell otherwise. can creating function using deterministic
keyword:
create function rand_det return number deterministic begin return dbms_random.value (); end;
using function instead of dbms_random
in first query tells query being executed once, despite many calls. clarifies select
section. if use same deterministic function in both select
, where
clause. can test using following query:
select rand_det all_tables rand_det > .5;
you may have run several times see our proof, but, eventually, you'll see list of values less 0.5. provides evidence deterministic function being executed twice: once each section appears in. alternative, can modify our deterministic function follows, run subsequent query, reveal 2 lines written dbms_output
.
create or replace function rand_det return number deterministic begin dbms_output.put_line ('called!'); return dbms_random.value (); end; select rand_det all_tables;
Comments
Post a Comment