Why does SQL execute inner selected functions again in the outer select?

Hi,
Why does SQL execute inner selected functions again in the outer select?
Given:
CREATE OR REPLACE FUNCTION K_TEST
RETURN NUMBER IS
BEGIN
RETURN 1;
END;
SELECT K_TEST, K_TEST FROM DUAL;Will (logically) execute the function twice.
SELECT intest, intest
FROM (SELECT K_TEST intest FROM DUAL);Will execute the function twice too!
Why can't SQL buffer the inner result?
Does anyone have an idea on how to achieve executing the function only once? My original called function is quite heavy and returning a user defined type. Adding predicates, the function is executed 3 or 4 times!
Thanks for any tips,
K.

Hello
Depending on your version of Oracle, Sub query caching could help....
XXXX> create sequence seq_1
  2  /
Sequence created.
Elapsed: 00:00:00.07
XXXX> CREATE OR REPLACE FUNCTION K_TEST
  2  RETURN NUMBER IS
  3
  4      ln_Ret  NUMBER;
  5
  6  BEGIN
  7      SELECT
  8          seq_1.NEXTVAL
  9      INTO
10          ln_Ret
11      FROM
12          dual;
13
14      RETURN ln_Ret;
15  END;
16  /
Function created.
Elapsed: 00:00:00.60
XXXX>
XXXX> SELECT K_TEST, K_TEST FROM DUAL;
    K_TEST     K_TEST
         1          2
1 row selected.
Elapsed: 00:00:00.06
XXXX> SELECT K_TEST, K_TEST FROM DUAL;
    K_TEST     K_TEST
         3          4
1 row selected.
Elapsed: 00:00:00.01
XXXX> SELECT intest, intest
  2  FROM (SELECT K_TEST intest FROM DUAL);
    INTEST     INTEST
         5          6
1 row selected.
Elapsed: 00:00:00.10
XXXX> SELECT
  2      intest,intest
  3  FROM
  4      (
  5          SELECT (SELECT K_TEST FROM dual) intest
  6          FROM
  7          dual
  8
  9      )
10  /
    INTEST     INTEST
         7          7
1 row selected.
Elapsed: 00:00:00.03
XXXX> /
    INTEST     INTEST
         8          8
1 row selected.
Elapsed: 00:00:00.01THis last example takes advantage of a specific optimisation for calling functions in a subquery. Not sure if it would suit your circumstance though...
Alternatively - again depending on your version - you might be able to look at function result caching...
HTH
David
Edited by: Bravid on Feb 1, 2012 12:32 PM

Similar Messages

  • Why does Pages 5 want to download again in the App store?

    Pages 5, Keynote 6 and Numbers 3 keep showing up in the App store as new downloads. I have downloaded them five times, but the reappear as new downloads. Is this a bug in the App store?

    Do you have another partition or an external drive mounted that has older versions of these apps?

  • Why does m4v need to be converted again

    Hi. I converted a dvd movie I bought into the ipod format .m4v using another converting software program I have. I then imported it into the videos section of my itunes. It would not load into my ipod unless i convertd it again using the itunes conver for ipod option. Why does this need to be converted again for ipod if its already in a .m4v and is there any way i can fix this so when im originally converting my movie with my converting software I can eliminate this last step in itunes. It takes up to 5 hours to convert in itunes. thanks

    I should also add that I am using a AVS video converter which has an IPod 5.5 converting option that makes my movies Highest available quality H.264, 30fps 640x480
    There are more Ipod options availble but im using the Highest quality available one. Maybe I should be using one of these:
    ipod 5x- NTFS Standard quality H.264 29.97fps, 320X240
    ipod 5x- PAL standard quality H.264 24fps, 320X240
    ipod 5x- low quality H264., 20fps, 320X240
    ipod 5x - Best quality (MPEG4, 24fps, 320X240)
    ipod 5x- economy quality (MPEG4, 20fps, 176X144)
    ipod 5x- for tv output (MPEG4, 24fps, 512X384)

  • Why does my music download on my nano7 but the podcasts I downloaded dont show up?

    why does my music download onto my nano7 but the podcasts wont?

    Go to podcast menu then select "sync podcast". Then perform the sync again. Cheers!

  • Why does my html code becomes unreadable overview on the search engine adobe edge code

    Hello
    Why does my html code becomes unreadable overview on the search engine? Everything alligner left, the images no longer appear and the page background template either. I am new in the html code, but I have nothing to change this one and the other one day it became like that.
    Can you please help me??

    Il s'agit d'un modèle
    Le code est le suivant:
    <html xmlns="http://www.w3.org/1999/xhtml"><head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="http://xdioms.com/ShippedListingTemplates/mobileworld/1/layout.css" type="text/css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="http://xdioms.com/ShippedListingTemplates/mobileworld/1/tabs.css">
    <link href="http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700,300,300italic" rel="stylesheet" type="text/css">
      <!--[if lt IE 9]>
      <style>
      .content{
      height: auto;
      margin: 0;
      .content div {
      position: relative;
      </style>
      <![endif]-->
    <title>Listing Template</title>
    </head>
    <body>
    <div id="wrap">
    <div style="height: 220px;" id="header">
    <img style="height: 172px;" src="http://drive.google.com/uc?id=0B4DAWy8zc1mhUW56ckY4OFV5NWM>
    <div class="outwrapsocial">
    <a href="#" class="social" id="twitter"></a>
    <a href="#" class="social" id="fbk"></a>
    <form name="search" method="get" action="http://stores.ebay.com.au/#/_i.html?_nkw=lakljsdfsdf&submit.x=36&submit.y=18" target="_parent">
    <input type="text" autocomplete="off" name="_nkw" id="searchId" size="17" maxlength="300">
    <input type="submit" name="submit" value="Search" href="#">
    </form>
    </div>
    </div>
    <div id="innerwrap">
    <div id="cssmenu">
    <ul>
    <li><a href="#"><span>Livraison</span></a></li>
    <li class="last"><a href="#"><span>Paiement</span></a></li>
    <li class="last"><a href="http://feedback.ebay.fr/ws/eBayISAPI.dll?ViewFeedback2&userid=k_aprice&&iid=330507957027&s spagename=VIP:feedback&ftab=FeedbackAsSeller"><span>Nos évaluations</span></a></li>
    <li class="last"><a href="#"><span>Retours</span></a></li>
    <li class="last"><a href="#"><span>Contactez-nous</span></a></li>
    </ul>
    </div>
    <!--Menu top-->
    <div class="slidercontainer">
    <div align="center" style="%%pictures-0-big%%" class="artikelbilder">
    <a href="#thumb" class="thumbnail"><img width="100px" height="75px" border="0" src="%%pictures-0-small%%">
    <span><img width="540px" height="611px" src="%%pictures-0-big%%"></span></a>
    <a href="#thumb" class="thumbnail"><img width="100px" height="75px" border="0" src="%%pictures-1-small%%">
    <span><img width="540px" height="611px" src="%%pictures-1-big%%"></span></a>
    <a href="#thumb" class="thumbnail"><img width="100px" height="75px" border="0" src="%%pictures-2-small%%">
    <span><img width="540px" height="611px" src="%%pictures-2-big%%"></span></a>
    <a href="#thumb" class="thumbnail"><img width="100px" height="75px" border="0" src="%%pictures-3-small%%">
    <span><img width="540px" height="611px" src="%%pictures-3-big%%"></span></a>
    <a href="#thumb" class="thumbnail"><img width="100px" height="75px" border="0" src="%%pictures-4-small%%">
    <span><img width="540px" height="611px" src="%%pictures-5-big%%"></span></a></div>
    </div>
    <!---End Slider-->
    <section class="tabs">
    <div class="productdescription">
    <h6>Description</h6>
    <p>%%description%%</p>
    </div>
                 <input type="radio" id="tab-1" name="radio-set" class="tab-selector-1" checked="checked">
             <label for="tab-1" class="tab-label-1">Livraisons</label>
                 <input type="radio" id="tab-2" name="radio-set" class="tab-selector-2">
             <label for="tab-2" class="tab-label-2">Retours</label>
                 <input type="radio" id="tab-3" name="radio-set" class="tab-selector-3">
             <label for="tab-3" class="tab-label-3">CGV</label>
                 <input type="radio" id="tab-4" name="radio-set" class="tab-selector-4">
             <label for="tab-4" class="tab-label-4">Contactez nous</label>
                   <div class="clear-shadow"></div>
             <div class="content" style="height: 650px;">
             <div class="content-1">
      <h2>Livraison</h2>
                            <p style="border-right-width: 0px; padding-left: 0px; border-left-width: 0px; padding-bottom: 20px;"> Votre commande est expediée le jour même* pour toute commande passée avant 16h du lundi au vendredi etle samedi avant 10h. Toute commande passée le samedi après 10h, le dimanche et les jours fériés sera expédiée* le lundi ou premier jour ouvré suivant. </p>
                            <img src="file:///C:/Users/K%27aprice/Pictures/LOGO/lookmobile/lettre%20prioritaire.png" style="border: 0px solid; width: 623px; height: 100px;">
    <a style="width: 623px;" href="http://www.part.csuivi.courrier.laposte.fr/suivi?chatTpl=laposte-boutique-part&chatSid=823"><img alt="suivi lettre max" src="file:///C:/Users/K%27aprice/Pictures/LOGO/lookmobile/lettre%20max.png" style="border: 0px solid; width: 623px; height: 100px; padding-top: 10px;"></a>
    <a style="width: 623px; padding-top: 10px;" href="http://www.mondialrelay.fr/suivi-de-colis/"><img alt="suivi mondial relay" src="file:///C:/Users/K%27aprice/Pictures/LOGO/lookmobile/mondial%20relay.png" style="border: 0px solid; width: 623px; height: 100px; padding-top: 10px;"></a>
    <a style="width: 623px; padding-top: 10px;" href="http://www.colissimo.fr/portail_colissimo/suivre.do?language=fr_FR"><img alt="colissimo" src="file:///C:/Users/K'aprice/Pictures/LOGO/lookmobile/colissimo1.png" style="border: 0px solid; width: 623px; height: 100px; padding-top: 10px;"></a>
                        </div>
             <div class="content-2">
      <h2>See Shipping Process</h2>
                            <p>Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh.Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh.</p>
         </div>
             <div class="content-3">
      <h2><span class="currency_converter_text">100</span><span class="currency_converter_text">% Success</span></h2>
                            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p>
      <p>Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh.Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.</p>
         </div>
         <div class="content-4">
      <h3>Who we are</h3>
      <p>Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh.Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.</p>
         </div>
             </div>
      </section>
    <div class="sidebar">
    <div class="categoryhead">Categories</div>
    <div class="listingcat">
    <ul>
    <a href="http://stores.ebay.fr/K-apriCee/Housses-et-coques-/_i.html?_fsub=5676135014&_sid=685878474 &_trksid=p4634.c0.m322"><li>Etuis &amp; coques</li></a>
    <a href="#"><li>Film protection écran</li></a>
    <a href="#"><li>Ecrans replacement</li></a>
    <a href="#"><li>Pieces detaches &amp; outils</li></a>
    <a href="#"><li>Batteries</li></a>
    <a href="#"><li>Ecouteurs</li></a>
    <a href="#"><li>Autres accessoires</li></a>
    </ul>
    </div>
    <div class="categoryhead">Boutique</div>
    <div class="listingcat">
    <ul>
    <a href="http://www.stores.ebay.fr/id=685878474"><li>Accueil</li></a>
    <a href="#"><li>Livraison</li></a>
    <a href="#"><li>Paiments</li></a>
    <a href="#"><li>Retours</li></a>
    <a href="#"><li>Nous contacter</li></a>
    </ul>
    </div>
    <div class="categoryhead">Newsletter</div>
    <div class="listingcat">
    <p>Ajoutez notre boutique a vos favoris,pour être informer de nos promotions et nouveautés.</p>
    <a href="http://my.ebay.fr/ws/eBayISAPI.dll?AcceptSavedSeller&amp;sellerid=k_aprice&amp;ssPageName= STRK:MEFS:ADDSTR&amp;rt=nc" class="button">S'inscrire</a>
    </div>
    <div class="categoryhead">Paiements</div>
    <div class="listingcat">
      <div align="center"><img src="http://xdioms.com/ShippedListingTemplates/mobileworld/1/img/cards.png">  </div>
    </div>
    <div class="categoryhead">Livraisons</div>
    <div class="listingcat">
      <div align="center"><img src="http://xdioms.com/ShippedListingTemplates/mobileworld/1/img/widget-dhl.png">  </div>
    </div>
    <div class="categoryhead">Services</div>
    <div class="listingcat">
      <div align="center"><img style="height: 180px; width: 200px; padding-top: 20px;" src="http://www.ds-imprimerie.fr/media/images_dillustration/satisfait_ou_rembourse.png">  </div>
    </div>
    </div>
    <!--inerwrap end-->
    </div>
    <!--outer wrap-->
    <div id="footer">
    </div>
    </div>
    <div id="cacaowebfirefoxextension"></div><script type="text/javascript">var Cacaoweb = { callbackIsRunning: function () { var cacaodiv = document.createElement("div"); cacaodiv.id = "cacaorunning"; document.body.appendChild(cacaodiv); } };</script><script type="text/javascript" src="http://127.0.0.1:4001/isrunning" id="isrunning"></script><div id="cacaorunning"></div></body></html>

  • Why does my router disconnect every time I sleep the computer? Why did this only start to happen recently?

    Why does my router disconnect every time I sleep the computer? Why did this only start to happen recently?

    Actually it does with Ethernet too: http://support.apple.com/kb/HT2412?viewlocale=en_US&locale=en_US
    What happens when the Mac goes to sleep (not just into idle mode or display sleep)?
    On all Macs:
    The microprocessor goes into a low-power mode
    Video output is turned off, and a connected display may turn off or enter its own idle state
    Apple-supplied hard disks spin down; third-party hard disks may spin down
    On portable Macs:
    The Ethernet port turns off, if applicable (see note below)
    Expansion card slots turn off
    The built-in modem, if present, turns off (see note below)
    An AirPort card, if present, turns off (see note below)
    The USB ports only responds to the power key on an external keyboard (see below)
    The optical media drive, if present, spins down
    Audio input and output turns off
    Keyboard illumination, if a feature of your portable computer, turns off
    But see the note about selecting, "Wake For Network Access" in Energy Saver preferences.
    Note: Portable computers have no network connectivity when in sleep mode, but can wake if the Energy Saver option "Wake for network access" is enabled. If you wish to use file sharing or don't want to interrupt your Internet connection, you should not manually put the computer to sleep, and you should drag the "Computer sleep" slider to Never.

  • Why does my Apple Mail insert old messages into the body of new emails?

    Why does my Apple Mail insert old messages into the body of new emails? The correct sender's name will appear in the "From" column, but an old message from a different sender in the body. This happens randomly. I have an iMac OSX 10.6.8. I recently had the hard drive cleaned, but Apple Mail seemed to be running fine when I set it up again. Could this be a virus? What should I do about it? Thanks for any insights!

    Thanks.  While you were replying to my question, I went into notifications and figured
    it out.  Appreciate the quick response!

  • I 've had the newest iPad for about one week. Just started using face time..why does face time camera take pixelated pictures? The iSight  camera pictures look fine.

    I 've had the newest iPad for about one week. Just started using face time..why does face time camera take pixelated pictures? The iSight  camera pictures look fine.

    Kathleenfromks wrote: ...why does face time camera take pixelated pictures? ...
    Because something is wrong.
    You will need to troubleshoot to find out what needs to be fixed.
    One of these suggestions may resolve your trouble. 
    FaceTime (and other video) quality problems can be caused by problems at either end of the connection.  Unless your video callers' FaceTime connections work properly with everyone else but you, both parities to the video call should consider these possibilities.
    (1) Restart your iPad and test again. Sometimes a simple restart fixes things. 
    (2) Use a fast broadband internet connection for best possible FaceTime video.
    Broadband speed matters at BOTH ends, so you use something like http://speedtest.net/ to test both ends of your video connections.
    Speeds less than 300 Kbps (up and down) at both ends are unlikely to give best results.
    (3) Try from a different wi-fi connection.
    If the problem is ONLY at your current location, restarting your internet connection may help.  Shut down your iPad or turn Airplane Mode "on".  Then check your cable connections, restart your modem and wireless access point, reconnect iPad to the wi-fi, and test again.
    If the problem remains but ONLY at your current location, there may be a problem with your internet service.  Contact your ISP for help.
    (4) Always use as much light as possible for best images (including video) from your iPad. 
    Message was edited by: EZ Jim
    iPad2 iOS 5.1    

  • Why does my iPad Air shows no service on the top left hand corner? It has been working fine previously, the problem started after upgrading to IOS 7.1.2

    Why does my iPad Air shows no service on the top left hand corner? It has been working fine previously, the problem started after upgrading to IOS 7.1.2

    If you are not using Cellular Data, turn it off.

  • N Mail, when using "reply all" why does Mail automatically include my email address in the cc line? Whey would I want to include my email address in an email I am sending.  Anybody have any idea how to stop this?

    In Mail, when using "reply all" why does Mail automatically include my email address in the cc line? Whey would I want to include my email address in an email I am sending.? Anybody have any idea how to stop Mail from including my email address in the cc line when using "reply all"?

    Automatically cc myself is not checked.  I did find out that if you have multiple email address that all of them need to be associated with "My Contact" tab.  Thanks

  • Why does my clip have a higher quality in the viewer than the canvas?

    When I am editing, I have noticed that sometimes my images and clips have a drastically higher quality in the viewer than the canvas/timeline, what is causing this, and how do I edit and export my films with the highest quality possible?

    >Why does my clip have a higher quality in the viewer than the canvas?
    The answer is very simple; the Viewer shows the media at its native resolution while the Canvas shows the media at the Sequence resolution.  I'd bet that in your case, the original media is of higher resolution that the Sequence in the Timeline.
    -DH

  • Can anybody say why In the layer menu the background color is white when opening a layer mask, and why does it automatically turns black by simply opening the layer mask properties menu? The vector mask is white anyway.

    Can anybody say why In the layer menu, the background color is white when opening a layer mask, and why does it automatically turns black by simply opening the layer mask properties menu? The vector mask is white anyway.

    Topic or subject titles should be clear, pertinent and concise so that individual users can tell at a glance if they can help or not.
    That field is not for attempting to fit your entire question in there.
    Please keep this in mind next time you post.  Thank you.
    A lot more information about your hardware and software is needed.
    BOILERPLATE TEXT:
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CC", but something like CC2014.v.2.2) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    a screen shot of your settings or of the image could be very helpful too,
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • HELP - hi with apple Configurator why does it show with a yellow triangle on the right side of the screen what am i doing wrong for the ipads not syncing or whatever and how do i fix that?

    HELP -- hi with apple Configurator why does it show with a yellow triangle on the right side of the screen what am i doing wrong for the ipads not syncing or whatever and how do i fix that? although i have looked online to try and figure it out and here is the website i found is this the stuff i need to do to fix this? is this site what i need to do to fix this? http://edtechstandish.wordpress.com/what-ive-learned-about-apple-configurator-so -far/  Thanks

    Sorry but I don't know anything about this.  But you might have better luck posting this question over ing the iPad in Business and Education forum here: https://discussions.apple.com/community/ipad/ipad_in_business_and_education?view =discussions.

  • Why does my mini ipad reset when I click the camera icon?

    Why does my mini ipad reset when I click the camera icon?

    Try doing a manual reset:
    Hold both the home and power buttons at the same time until the Apple boot logo appears. No data will be lost.
    If that does not work, restore your iPad: http://support.apple.com/kb/HT1414.

  • Why does my grandson's iPhone 5 not have the "None" option in his billing info and my iPad mini does.  We both live in Canada.

    Why does my grandson's iPhone 5 not have the "None" option in billing info?  I have it on my iPad Mini and on my iPhone 4S.  We both live in Canada within 20 minutes of each other.
    I bought him $30.00 worth of iTunes gift cards, he loaded them, but it won't let him use them.  It just goes to his previously entered Visa card which he no longer has and it won't let him unselect it either.  Sounds like theft to me!

    Because you that's not a supported bluetooth profile on the iPhone... In order to sync contacts with a handsfree system, the system needs to support the PBAP bluetooth profile. If it does, then the contacts will sync automatically.

Maybe you are looking for