Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query result cache with functions

1024640Dec 2 2013 — edited Dec 3 2013

Hi all,

one of my colleagues has found a little bit weird behavior of a query result cache. He has set result_cache_mode = 'FORCE' (but it can be reproduced with a result_cache hint too) and suddenly functions called from the query get executed twice (for the first time) .

An easy example:

alter session set result_cache_mode = 'FORCE';

create sequence test_seq;

create or replace function test_f(i number)

return number

is                  

begin

  dbms_output.put_line('TEST_F executed');

  --autonomous transaction or package variable can be used too

  return test_seq.nextval;

end;

/

prompt First call

select test_f(1) from dual;

prompt Second call

select test_f(1) from dual;

drop sequence test_seq;

drop function test_f;

First call

TEST_F(1)

----------

         2

TEST_F executed

TEST_F executed

Second call

TEST_F(1)

----------

         1

As you can see - for the first time the function is executed twice and return the value from the second execution. When I execute the query again it returns the value from the first execution... but it doesn't matter, problem is in the double execution. Our developers used to send emails via select (it's easier for them):

select send_mail(...) from dual;

... and now the customers complains that they get emails twice

And now the question - is there any way, hot to get rid of this behavior (without changing the parameter back or rewriting code)? I thought that the result cache is automatically disabled for non-deterministic functions...or is this an expected behavior?

Thanks,

Ivan

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 31 2013
Added on Dec 2 2013
9 comments
845 views