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!

How many times is a subquery executed?

xxsawerAug 28 2013 — edited Aug 28 2013

Hi again,

I have following problem:

CREATE SEQUENCE SEQ_TEST START WITH 1 INCREMENT BY 1 MAXVALUE 9999 CYCLE NOCACHE;

--

CREATE OR REPLACE FUNCTION Test RETURN NUMBER

AS

BEGIN

   DBMS_OUTPUT.PUT_LINE('Test');

   RETURN SEQ_TEST.NEXTVAL;

END Test;

/

--

SELECT xyz, xyz

  FROM (SELECT Test xyz FROM DUAL);

As a result I get always two consecutive values. So it means that the subquery is executed everytime I refer to it in the outer query. Why?

I would expect that the subquery would be executed only once and then I should get same values. Is there any optimizer hint to achieve this?

Thanks a lot in advance,

Dan

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2013
Added on Aug 28 2013
5 comments
944 views