The order of execution (of PL/SQL function calls) changes...why??

select e.EMPID empid,
e.name name,
aatest.SETVALUES(2) z,
aatest.TEST1() b,
aatest.TEST2() x,
aatest.TEST3() y
from emp e
where e.empid = 101
order by e.name;
when I execute this select statement...the order of function calls is as follows:
setvalues 1st (call no:1)
test1 (call no:2)
test2 (call no:3)
test3 (call no:4)
Now...I introduce a join between the two tacles as mentioned in the query
select e.EMPID empid,
e.name name,
e2.deptno deptid,
aatest.SETVALUES(2) z,
aatest.TEST1() b,
aatest.TEST2() x,
aatest.TEST3() y
from emp e, emp2 e2
where e.empid = e2.empid
order by e.name;
The order of execution of function calls changes to
(I observed this using DBMS_OUTPUT.PUT_LINE)
test3 (call no:1)
setvalues 1st (call no:2)
test1 (call no:3)
test2 (call no:4) (the first and last calls swap!)
i.e: it calls the last function in the select statement at the beginning
instead of calling it at the last. Is it the normal behaviour? or whats going on
here?
Can somebody explain me, please....
Details:
the following four functions are defined in a package called 'aatest' and compiled.
aatest.SETVALUES(2)
aatest.TEST1()
aatest.TEST2()
aatest.TEST3()
the Tables EMP and EMP2 are two tables defined in the same schema.

Your "thinking" is wrong here. You can not use the column order to model your program flow. As SQL is set/tupel based, there is no given sequence of the execution order. Otoh you want to have a specific order in wich your functions must be executed otherwise the result will be wrong (or undefined). Thus here you need a procedural approach. This can be done by using PL/SQL for example.
You would code your functions in that way, that they are working correctly independent from the place where they are called ie if function1 needs the setvalues function, this function must be called inside the function1 then.
Are you sure you need all these functions in this procedural approach inside the sql-statement? This is mostly not needed and can be accomplished by using pure SQL. If not, may be your design is broken.

Similar Messages

  • Tracking the order of execution of sql scripts in SQL*Plus

    In our production environment we sometimes have to run some .sql scripts in a particular order. Since the order of execution is important , i have created another .sql file caller caller.sql(shown at the bottom) which will call all the scripts in the right order.
    i thought of putting a exec DBMS_LOCK.SLEEP (5); after the end of every execution of the script so that i can see the
    'Ending script1'message .
    The spooling within the caller script(execute_stack.log) has become meaningless because each script has a spool <filename.log> and spool off within it. These spool logs (for every script) is important for tracking purposes as each script belongs to a different development team and i have to send them the spooled log file after the execution.
    I don't want to see the entire scripts running by in my screen. Since these scripts have their own spooling, i can later check the logs if the scripts where executed properly.
    So i need two things.
    1.I just need to see the following and nothing else in the screen.
    Ending script1
    Ending script2
    Ending script3
    .2. I need to log the order of execution. ie. the execute_stack.log should look like the above.Since there is a spool off within each script, this wouldn't be possible.Right?
    Ending script1
    Ending script2
    Ending script3
    .The caller.sql script which calls all the scripts in the right order
    alter session set nls_date_format = 'DD-MON-YYYY hh24:MI:SS';
    set serveroutput on
    set echo on;
    set feedback on;
    spool execute_stack.log
    @script1.sql
    exec dbms_output.put_line ('Ending script1');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script2.sql
    exec dbms_output.put_line ('Ending script2');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script3.sql
    exec dbms_output.put_line ('Ending script3');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script4.sql
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec dbms_output.put_line ('Ending script3');
    commit;
    spool off;Is this a professional way of tracking the execution of .sql scripts?

    Pete_Sg1 wrote:
    Is this a professional way of tracking the execution of .sql scripts?No. There is very little professional about using .sql scripts on a production system - when stored procedures are safer, more robust, easier managed and controlled and secure.. and where a log table can be used to properly log the runtimes (and other stats) of each processing step.
    Let's just take a look at the number of moving parts you need to schedule and run a .sql script. A cron job needs to be configured with the proper environment setting. It needs to run a shell script. That shell script needs to load SQL*Plus. SQL*Plus needs to connect to the database (starting a dedicated server process most likely). SQL*Plus then needs to read a .sql file, parse these commands and either execute these locally (SQL*Plus commands) or remotely (PL/SQL and SQL commands).
    How can this be considered professional when the very same can be achieved with a
    - stored procedure
    - using DBMS_JOB to schedule the procedure for execution
    There are so many things that can go wrong with the first method. And so few things that could go wrong with the last one. No contest as to which method is not only better, but also professional.
    PS. See that you use Windows to run these scripts. It is even worse as it introduces another hardware and software layer making the scenario even more insecure & unsafe with more moving parts that can go wrong or simply fail.

  • What is the order of execution of global transfer routine where multiple routines are involved?

    Hi,
    Suppose we have start routine, transformation routines and end routine defined between datasource and data target, and also we have a global transfer routine created on an infoobject.
    What is the order of execution of routines in this scenerio?
    Also if conversion routine like ALPHA is defined for an Infoobject, when does this come into flow.?
    Please enlighten me.
    Thanks,
    Akshara

    Hello Akshara ,
    The sequence of routines are as
    1. Start Routine
    2. Master Data Look Up or
    3. Field Level Routine
    4. End Rountine
    Apart from this , there is Expert routine, which is used in special cases, when there are not the sufficient functions to perform a transformation. It can be used as a interim solution , and it performs all the  functions of Start routine, end routine , field routine.
    Note : if you have created  transformation, and then created Expert routine, then system will delete all the existing transformations.
    Further to this, you can explore more, by debug the transformation as suggested by Vijay Kumar.
    Hope this helps !
    Regards
    YN

  • How to find the number of executions of a sql oracle 10g

    Is there any script handy which is useful to get the number of executions of a sql in particualr time in a rac environment.

    A lot depends on what time period you're trying to count the executions over...
    In V$SQL, there is a column EXECUTIONS that will count the number of executions since the SQL statement was loaded into the shared pool, which may be too long a period or too short a period for your question.
    If you are trying to get historical information and you have licensed the performance & tuning pack so that you can get the AWR, you could query the DBA_HIST_SQLSTAT table over an appropriate set of SNAP_ID's to get the totals for an arbitrary period of time.
    Justin

  • What is the best way to Optimize a SQL query : call a function or do a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement or do a simple join?

    Hi,
    If you're even considering a join, then it will probably be faster.  As Justin said, it depends on lots of factors.
    A user-defined function is only necessary when you can't figure out how to do something in pure SQL, using joins and built-in functions.
    You might choose to have a user-defined function even though you could get the same result with a join.  That is, you realize that the function is slow, but you believe that the convenience of using a function is more important than better performance in that particular case.

  • Statechart Module: What is the order of execution for a parent state and its substates?

    Hello,
    This page describes the order of execution of transitions and actions for one level of nesting. What about compound states? Do the static reactions of the parent state execute before the transitions of the sub-states?

    Hello, 
    I'm not incredibly familiar with the Statechart module, but I will look into it for you on our internal database. In the mean time, there are some examples that may answer some of your questions here:
    https://decibel.ni.com/content/docs/DOC-8716
    and here:
    http://www.ni.com/white-paper/7425/en
    -N
    National Instruments
    Applications Engineer

  • HT4910 documents edited on iphone, ipad, & mac   what is the order of creation and editing and must each change be manually initiated to update the icloud

    documents edited on iphone, ipad, & mac   what is the order of creation and editing and must each change be manually initiated to update the icloud?

    No idea what you mean by the firsy part of your question.
    Documents edited on the Mac need manually uloading to iCloud at iCloud.com,documents edited on the mobile devices are updated automatically.

  • I currently have wireless, but i am looking into this to maybe have faster wireless. if this is hooked up, will the existing wireless/ethernet to pcs still function without changing them to use the airport express?

    i currently have wireless, but i am looking into this to maybe have faster wireless. if this is hooked up, will the existing wireless/ethernet to pcs still function without changing them to use the airport express?

    let me fix this a bit. i currently have dsl and a 2wire wireless router, and i currently do not have one or a mac. im getting one for when i start college and this is a must if it will improve my internet. but i now connect wirelessly to the 2wire router. if this is set up, will the current 2wire wireless still be useable?

  • I downloaded latest update of iTunes (windows 7, 64bit) and have now the problem runtime error R6025 pure virtual function call (Microsoft Visual C   runtime library) - Who would have a solution to that problem? Thanks *********

    I downloaded latest update of iTunes (windows 7, 64bit) and have now the problem runtime error R6025 pure virtual function call (Microsoft Visual C   runtime library) - Who would have a solution to that problem?
    Thanks from Switzerland
    <Edited by Host>

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it, which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    (I've asked the hosts to remove your email address)
    tt2

  • How to change the order of execution

    How to make a table driving table in the list of joining tables in the from clause?
    for
    select count(1)
    from
    table_a a , table_b b , table_c c
    where a.col1=b.col1
    and b.col2 = c.col2
    I know that we can use ordered hint to make oracle the use the ordered mentioned in the from clause.
    How about joinng order in the where clause.
    Do I need to give any extra hints.
    I understand a bit of checking oracle execution path.
    Is there any material which can give me insight of the same.
    thanks in advance

    Hi,
    hints should be used when there is no way to obtain a correcte execution path having objects analyzed and properly setup.
    In that case, the /*+ ORDERED */ hint after the SELECT clause forces the execution plan to follow the execution order based on the FROM clause.
    Be aware that, if if You have more than 2 tables in the from clause, You can have a Cartesian Product if the from clause is not properly set.
    Hope this helps
    Max

  • Passing parameters to PL/SQL function called in VO

    Hi,
    I am writing a VO that is calling a PL/SQL function. The VO query looks like this.
    select xx_dummy_func (:1,:2) from dual
    Now, how can I assign these two parameter values at run time?
    Generally when we have a query parameters We do xxVO.setwhereclauseparam. But in the above scenario, its not a whereclause but instead a procedure parameter. Please let me know how to do it.
    Thanks in advance,
    Regards,
    -Abm

    Thats correct, basically, setwherecaluse param api, just replaces bind variables with the index values, whereever they are in the query!
    --Mukul                                                                                                                                                                                                                                                                                                                                                       

  • How display result set of a PL/ SQL function call in a dialog box

    Hello,
    I am calling a PL/ SQL function from Apex, which returns - List of varchar.
    In Apex, it should show this list of varchar and "Yes" and "No" buttons on a message window.
    Can you please suggest a way to achieve the same.
    Thanks,
    Girish

    Hello,
    This application process "vrl_popup" is to get the values from PL/ SQL function. For popup window - confirm(). Also declared the LV_list as Application Item.
    Which is coded in the region part of the button. After pressing this button popup window should come with the list.
    <script type="text/javascript">
    <!--
    function doAjaxRequestParam( process, parameter)
    var ajaxRequest = new htmldb_Get(null,&APP_ID.,'vrl_popup='+process,0);
    ajaxRequest.add('lv_list', parameter );
    var jsonResult = eval('('+ ajaxRequest.get() +')');
    return jsonResult;
    var answer = confirm ("can try this?")
    alert (v_list)
    if (answer)
    alert ("done")
    else
    alert ("Unsuccessful")
    // -->
    </script>
    In apex I created following Application process by name = vrl_popup,
    declare
    lv_List varchar2(2000) := '';
    begin
    begin
    lv_List := select vrl_type_process_pkg.get_regd_reg_lste() from dual;
    exception when no_data_found then null;
    end;
    htp.prn(lv_List);
    end;
    Kindly help in fixing this.
    Edited by: Girish on Jun 17, 2010 12:57 AM

  • PL/SQL Function call error while reading or assigning returned value

    Hi,
    I am getting the following error while tryih to read the value of the PL/SQL Function. I am calling a function in one of my PL/SQL Packages passing mutliple IN parametes and the function returns some value back. Now on BPEL side when I try to read the return value I am getting an error:
    *<summary>*
    empty variable/expression result.
    xpath variable/expression expression "/ns3:OutputParameters/ns3:TEST_FUNCTION" is empty at line 124, when attempting reading/copying it.
    Please make sure the variable/expression result "/ns3:OutputParameters/ns3:TEST_FUNCTION" is not empty.
    *</summary>*
    Even though in the console when I check the Invoke Output Parameter it does shows me a valid value being retuned by a Function but when I am trying to Assgn this value to some variable using Assign Activity I get the above error.
    Even though all goes fine but looks like I am not able to read or assign the value returned from the Function.
    So just wondering if this even works as to me I have a very simple example and that seems not to work. Function is called successfully and is returning the value as I can see it in the BPEL console but when tryin to read or assign that value to some other variable I get the above error.
    Any ideas?
    Thanks

    This issue has come up a lot. The problem is with a mismatch between the version of JDeveloper and SOA. You'll encounter namespace issues if you use 10.1.3.1 in combination with 10.1.3.3 (or 10.1.3.4). You MUST synchronize both JDev and SOA to 10.1.3.3 or 10.1.3.4 (mixing 10.1.3.3 and 10.1.3.4 is OK). We changed when going to 10.1.3.3 by adding elementFormDefault="qualified" to the generated XSD. We used the default "unqualified" in 10.1.3.1. So you'll encounter namespace issues unless you're using 10.1.3.3 or higher JDev AND SOA. The fact that I see &lt;*db:*...&gt; tells me that you're using 10.1.3.1 JDeveloper. The correct solution is to upgrade your components.

  • I've ordered a book from iPhoto 3 times.  Last order was W29631918.  It says the order is accepted and being processed and then about 4 days later tells me the order has been cancelled.  If I call the help line it tells me the order has been cancelled and

    CLICK.  I've never had any problem like this with Shutterfly, ever.  And Apple gives you no other explanation.  CLICK.  That was my last Apple order.  What a waste.  Maybe someone from Apple can tell my why they do this.  It was for Christmas and I started ordering November 5 and waiting for it to be delivered each time.  This last one I followed and it even told me that the order had been processed and could not be cancelled.  The proprietary company.  Now I'm sorry I started using iphoto.  I'll redo the project with Shutterfly but I'm wondering if Apple treats many of its customers like this.

    i had the same problem .. and the worse is that i am from middle east where we can not get any help from apple.
    like if apple is only for some countries not for all world.
    what happened then? have you ever know what was the problem?

  • Keep the order in a file to sql transfert

    Hi
    Is there any mean to have records in a target table in the same order as they appear in a source flat file ?
    the file contains only one data per line
    thanks

    Yes you can do that,
    1.Create a data model in file techno and create a data store in that, point your source file
    2.Duplicate the File Datamodel, change the techo as Oracle ( or else what ever you have in target)
    3.Create a interface, drag and drop the file datastrore in your source. Drag and drop your oracle techno in target, say automatic mapping to Yes.
    4.Choose LKM as LKM File to Oracle (SQLLDR),IKM as Oracle Control Append.
    5.In the Option of IKM Select CREATE TARGET TABLE AS YES.
    It will create a table in Oracle with the same structure and data as in source file.
    Thanks,
    Guru

Maybe you are looking for