Using the loop will decrease performance

Hello
Using the loop with a query will decrease performance.

for r_row in (select * from table) Loop
end of loop.

This is done within another loop for, more cases, it returns a single value.
It will decrease the performance of the procedure.
kindly advice...

Kind regards
Balu

user575682 wrote:
Using the loop with a query will decrease performance.

for r_row in (select * from table) Loop
end of loop.

This is done within another loop for, more cases, it returns a single value.
It will decrease the performance of the procedure.

Perhaps better understand everything that makes this PL/SQL loop construction.

PL/SQL is two languages. It's PL (logic programming code) like Pascal, C or Java. You can use a 2nd language in it called SQL. The PL engine will be able to recognize when the 2nd language is used. And it compiles all the things that are necessary for motor PL call the SQL engine, pass the data to the SQL engine and get back data, etc. (compare this with the complexity of the use of SQL in Pascal, C or Java language).

So what's this loop? The PL engine recognizes the SQL SELECT statement. It creates an implicit cursor by calling the SQL engine to analyze (I hope a soft Parser), then run it.

As part of the loop of the PL, the PL engine now calls the SQL engine to extract data (lines) of the cursor. With 10g and later, the engine of the PL is smart enough to use the implicit treatment in bulk.

Before 10 g that he used to extract a line from the SQL engine, make the loop, the next line extraction, the loop, etc. In other words, if there is a 1000 lines to pick up, he'll call the SQL engine after 1000.

With 10g and later he get a 100 lines, which store in a buffer internal and then make the loop once 100. With a 1000 lines to fetch, it requires 10 extractions in bulk instead of one 1000 rank of extractions.

These extractions require a change of context - as the engine PL must not out back, and in the SQL engine to extract a line. It is an overhead projector and can become so slow the context switch nothing more.

And it's the construction of bases for this loop (and most other cursor loops) in PL/SQL.

The ideal is to reduce the number of context switches. It is an overload that can have an impact on performance.

What about using a loop in a loop. As 'bad '. This example uses the outer loop to retrieve the data. These data are then used to excite the extraction in internal or nested loop. The outside loop draws data from the SQL engine in PL variables Inside loop drives that same data back to the SQL engine.

Why? It would have been much faster not to pull and push data between the loops using PL.

It will be much faster do so only through SQL. Write the two loops as a single SQL statement and have the SQL engine directly driving these loops itself. This is called a JOIN in SQL. And the SQL engine can do not only more quickly, but it has a few algorithms of multiplied can be used which are even faster than a nested loop process (called merge joins, hash joins, etc.).

Bottom line. Optimize SQL. Reduce to a minimum the PL. *

Do as much of your data, crunch in SQL as possible. SQL is the fastest 'place' and process the data. No PL (or C/Pascal/Java).

Tags: Database

Similar Questions

  • An associative array, how the records using the loop counter?

    In the associative array, how the records using the loop counter? for example
    declare
        type population is table of number index by varchar2(64);
        city_population population;   
    begin
        city_population('Samillve') := 200;
        city_population('Lindenhurst') := 300;    
        
        for i in 1 .. city_population.count
        loop
            dbms_output.put_line(city_population(i)); -- compiler error
        end loop;
    end;
    /

    That would look like

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2      type population is table of number index by varchar2(64);
      3      city_population population;
      4      l_index varchar2(64);
      5  begin
      6      city_population('Samillve') := 200;
      7      city_population('Lindenhurst') := 300;
      8      l_index := city_population.first;
      9      while( l_index IS NOT NULL )
     10      loop
     11          dbms_output.put_line(city_population(l_index ));
     12          l_index := city_population.next(l_index);
     13      end loop;
     14* end;
    SQL> /
    300
    200
    
    PL/SQL procedure successfully completed.
    

    Justin

  • Win XP - program won't shortcut on desktop or program menu but will start if I use the Task Manager and perform a new task.

    I deleted the program and all the registry entries, reloaded the software several times.  If I try to use the button programs the application will not start.  If I go in the directory itself and try to run the software from there it does not either.  This occurs when the software is installed and the system is restarted.  Any help will be greatly appreciated.

    Hi Gary Malicote.
     
    As this question ask specific, I suggest you to post your query in the Motorola support forums for assistance.
  • How to use the loop to commit every 1 M folders?

    Oracle 9i
    40 M records must be insert the table. You will need to validate every 1 M. But I don't want to loop every recording and validation. I like select commit and records of 1 m and then select another 1 M, then validation; How to do? use the save point?

    Appreciate any ideas.
    Thank you
    S.

    You can perform this anonymous help block by using a loop and listen but it not a good idea to commit after 1 million or 100 k you put more load on your system and the performance will be declining.

    Concerning

  • Incorrect display using the loop format for

    Hello

    I have a digital painting using a hexadecimal display format that is autoindexed by a loop for. Within the loop for each unique value is passed to a Subvi needed the hexadecimal display format. Unfortunately, indexing is not keep this hex format but transfers back to a decimal number.

    No idea how to solve this problem?

    Thanks in advance and best regards

    Simon

    Thanks for this tip. The problem was an another Subvi where I created the num-array that will subsequently in the loop for., all the digital elements where the value instead of I32 I16. The controller could not handle these false values, so I got a nonsense.

    Thank you very much for your quick responses!

  • Excerpt from my table using the loop For

    Hello

    I have this loop to create a 2D array. The result is on the table below. I want that this 2D table should be fully completed and compiled, then it will be sent out of the loop.

    I don't want to extract the value of table 2D is a loop. This is the problem that I am facing.

    My ultimate goal is to extract the individual number of the final table of the 2D table line and be an entry for other functions.

    Please help me. Thank you

    PX

    Hi PX.

    Here's a solution without using screw express

  • Reading data from a Table by using the loop

    I have a dynamic array within the PDF form. I want to loop through the rows in the table and read the contents of the cell. I successfully get the number of rows in the table. But impossible to read the values in the cells. I put control TextField (txtName) editable in every cell and trying to read its value.

    screenshot is below.

    table_loop_error.jpg

    I use the code is:

     form1.Page1.Subform1.btnReadTable::click - (JavaScript, client)
    
    var rowCount = MyTable._Row1.count;
    app.alert("Row Count: " + rowCount);
    var i = 0;
    
    for(i=0 ; i<rowCount ; i++)
    {
        //app.alert(MyTable.Row1[i].txtName.rawValue); // NOT WORKING
        
        app.alert(MyTable.Row1.txtName.rawValue); // WORKING, But just giving the value for the first row.
    }
    

    Please tell me how can I get the value of each name in all ranks by making a loop.

    Thanks in advance.

    -

    Afonso

    Hi, Afonso,

    You must resolve the node for the particular case of i. The syntax is:

    xfa.resolveNode("MyTable.Row1[" + i  + "].txtName").rawValue;
    

    Here there is an example that will show you the loop in action:

    http://www.assuredynamics.com/index.php/category/portfolio/two-way-binding-in-tables/

    Hope that helps,

    Niall

    Ensure the dynamics

  • AS2.0 using the loop

    It's been a while for me, I use to know AS2.0 very well, but far from him, I've traveled (mostly do PHP, Java, c#, VB now), but I'm back in the flash thing and I need help to dynamically create a variable name to work with. I remember I use to know how to do it, but alas, my knowledge is gone.

    Question: I have a few video clips with some unique identifies within each of them, that I need to access it in a loop for example.:

    myMovieClip01_mc
    myMovieClip02_mc
    myMovieClip03_mc
    ... etc.

    So basically I write a loop for which will allow me to access each in the loop for I thought to rewrite the program with a table, but it's a lot of code.

    Thus, each loop I need to create something like this:

    "myMovieClip" + (i + 1) + "_mc".

    Please to jog my memory on this subject. Thank you very much.

    of course - you must use the operator to access here, as in:

    This ["myMovieClip" + (i + 1) + "_mc"].

  • using the loop in matrix report

    Dear all,

    I want to generate a turnout report.the user will enter just the start_date and the end_date.
    Suppose that the days between arguments start_date and the end_date are 30 days.i want to use those 30 days for the columns in the matrix report.i use the following loop.

    because loop me in 1.30
    (I) return;
    end loop;


    She just return 1 for each column as
    1 1 1 1 1 1 1... and so on
    Instead, I want it to appear
    1 2 3 4 5 6 7 8 9 10... and so on until 30.

    How would I do that?

    Thank you and best regards.

    Lets say that emp 1 was late 03 - Jan, emp 2 was absent on 04-Jan and emp 4 was behind on 07 - Jan. And if you run the report from Jan 01 - Jan - 10, it should give dates of Jan. 01 - Jan to 10. You can use the query like this (this is just an example, you must change according to your requirement. The part that provide daily, you can use as it is):



    SELECT EMP_LATE_ABSENT.EMPNO,
    TO_CHAR(ALL_DATES.ALL_DAYS,'DD') ALL_DAYS,
    EMP_LATE_ABSENT.HOURS_LATE
    FROM

    (
    SELECT ALL_DAYS
    FROM (
    SELECT TO_DATE(:start_date,'DD-MON-RR') + LEVEL - 1 ALL_DAYS
    FROM dual
    CONNECT BY LEVEL <= TO_DATE(:end_date, 'DD-MON-RR') - TO_DATE(:start_date,'DD-MON-RR') + 1
    )
    ) ALL_DATES,
    (
    SELECT 1 EMPNO,
    TO_DATE('03-JAN-2009') DATE_LATE_ABSENT,
    3 HOURS_LATE
    FROM DUAL
    UNION
    SELECT 2,
    TO_DATE('04-JAN-2009'),
    NULL
    FROM DUAL
    UNION
    SELECT 4,
    TO_DATE('07-JAN-2009'),
    6
    FROM DUAL
    ) EMP_LATE_ABSENT
    WHERE ALL_DATES.ALL_DAYS = EMP_LATE_ABSENT.DATE_LATE_ABSENT(+)
    ORDER BY EMP_LATE_ABSENT.EMPNO,
    ALL_DAYS

    So result would come up like this:

    Emp All Days Hours Late
    1 03 3
    2 04
    4 07 6
    01
    02
    05
    06
    08
    09
    10


    And when you create a matrix report, from 01 to 10 days would be in the form of columns, used as lines and values of hours/null as cell values.

    I hope this helps.

  • decimal to binary conversion using the loop

    How to create a LabVIEW program to convert a decimal number to binary equivalent using FOR loop?

    can someone help me please...

    Dhass, your sound question as a duty. Is this correct?

    If so, the zip code you have already so that we can identify the weak points in it.

    Tone

  • Office jet pro 8500 a: copy using the ADF will not work.

    I place the document in the top loader, it seems to be recognized by the machine, when I press the copy, it makes a funny noise but the document doen't go through the driver and the machine ask me to reload the document. A copy is fate. I checked if any blocking or jamming of paper but it's all clear.

    Been through the different troubleshooting steps, but nothing helped.

    Thank you very much

    Hello FROGYBEAR and welcome to the Forums of HP, I hope you enjoy your experience!

    I see from your post that you are experiencing supply problems.  I would like to help with that!

    I recommend you to perform a power reset. Unplug the power cord from the printer and the power outlet, then wait 60 seconds. After 60 seconds, plug back in the printer. Make sure that you connect the printer directly to a wall outlet. Make sure to bypass any surge protector or power bar.

    I would also suggest using this document on When you use the ADF, one "original jam: clear jam and press OK' Message displays on the all-in-one."  I understand the questions you see are a little different, but the steps should help solve that.

    Good luck and please let me know the results of your troubleshooting operations. Thanks for posting on the HP Forums!

  • Using the loop

    Hi all

    I have two VO... IE, VO1 and VO2. and I have a handful of two your

    I want to compare attribute VO1 VO2 attribute... both have guess that 4 attributes.

    what I want to do here is: first of all I want to compare all 4 attributess VO1 1 rank to all the 4 attributes of 1st row of VO2. If they're all matches then the 5th value of attribute attribute value VO1 VO2 5th.

    If the 1st rank of VO1 is not with the 1st rank of VO2 then compare VO1 1 rank 2nd in the VO2... and so on...

    If the match then set value and exit that loop... and yet once compare with 2nd row of VO1 1st row of VO2...

    How can I do this... can I use 2 loops?

    loop external and inner loop?

    If Yes, then how can I extract the data of both your and how I can compare their attributes?

    Thank you...

    Hello

    Yes... you can do using two Do While loops. using vo.next.

    Please find the below generic example code.

    OAViewObject dbVo = (OAViewObject) oaapplicationmodule.findViewObject ("SimpleSearchVO");

    Line line = null;

    dbVo.reset ();

    do

    {

    line = dbVo.next ();

    if(Row == null)

    {

    break;

    }

    Line row2 = dbVo.getCurrentRow ();

    String newprice = String.valueOf (row2.getAttribute (viewAttributeName))

    } while (true);

    Thank you

    Bharat

  • Build the value of 100 mb of data in the table using the loop

    DB version: 11.2

    How can I create about 100 MB of test data in a table using minum number of records.
    If I use the below for loop. It takes 100,000 records to fill only 2 MB.
    SQL> create table a2 (mynum1 number, mynum2 number);
    
    Table created.
    
    begin
    for i in 1..100000 loop
        insert into a2 values(i,i*2);
    end loop;
    end;
    
    
    select segment_name, bytes/1024/1024 MB from dba_segments where segment_name = 'A2' AND owner='SCOTT'
    
    
    SEGMENT  BYTES/1024/1024
    -------- ---------------
    A2                     2

    Hello

    Is that what you are looking for?

    SQL> CREATE TABLE tbl1(c1 CHAR(1024));  -- ~1KB per row
    
    Table created.
    
    Elapsed: 00:00:00.00
    SQL> INSERT /*+ APPEND */ INTO tbl1 SELECT 'X' FROM dual CONNECT BY LEVEL < 100000; -- 100K rows * 1KB = 100MB + some additional overhead
    
    99999 rows created.
    
    Elapsed: 00:00:13.02
    SQL> SELECT bytes/1024/1024 MB FROM user_segments WHERE segment_name = 'TBL1';
    
            MB
    ----------
        113.75
    

    Lukasz

  • How to use the loop in BPEL process

    Hi friends

    I did a bpel process that picks up the XMl file using the File adapter and imports the data from the XMl file into db oracle table using the DB adapter...

    But here the XML in the file that have only one line... If I want to insert the XML code in the file that have two or more lines I want to use a loop in my process BPEL how to use loop in my bpel process?

    In my BPEL process, that I have que j' ai utilise used receive, process and call activity where I can use in my BPEL process

    Thanks in advance

    AT

    Here is a basic example of while activity in BPEL

    http://blogs.Oracle.com/ajaysharma/

    Thank you
    AJ

  • Tables: using the loop and delivery

    I'm not very good with tables. Here is my broken code:

    //Create array with 4 movieclips
    var invArray:Array = new Array("i_greenLine", "i_orangeDot", "i_yellowBlock", "i_brownThing");
    //repeat this code for every item (+1)
    for (i=0; i<invArray.length; i++) {
         trace(invArray[i]);
         //Outputs:
         //i_greenLine
         //i_orangeDot
         //i_yellowBlock
         //i_brownThing
         invArray[i].onPress = function() {
              trace("hit");
         };//the movieclips are not clickable.
    }
    

    Is there a way to get the clips on the stage to be clickable via a table? There are many, many clips.

    Help?

    Thank you?

    If you use strings of the instance for the table names, then you will need to use the support rating to target instances with them...

    var invArray:Array = new Array("i_greenLine", "i_orangeDot", "i_yellowBlock", "i_brownThing");
    for (i=0; i}
    
    

    An alternative would be to use only the instance names and no channels to them...

    var invArray:Array = new Array(i_greenLine, i_orangeDot, i_yellowBlock, i_brownThing);
    for (i=0; i}
    
    

    If you plan to have a large number of them, so a better approach would be to name them all with digital ending (mc0, mc1, mc2, mc3, etc..)  You can then use the notation of support without the need for table...

    for (i=0; i}
    
    

Maybe you are looking for

  • NFL Game Pass Apple TV

    I have a generation of Apple TV 3. I'm an American living in Malaysia. I have a subscription to NFL game Pass and the application of the NFL that it works on the apple tv. Whenever I open the app on the apple tv now, I get a black screen with the tex

  • WIN 7 SP1

    I downloaded SP1 entirely on my laptop G62 win 7 and during the installation, I got an error fatel I think he said he had a problem installing update 262 and I had to run a restore (at least none of my files were lost) someone has an idea of what hap

  • How to create a Windows XP wireless network connection?

    just installed a router. hot create a wireless connection. With the help of XP Professional. Thank you Original title: wireless connections

  • Impossible to stream multimedia content to my TV

    Original title: Windows Media Player (already run version 11) First of all, my apologies if I'm posting this question in the wrong forum! I recently bought a Sony Bravia TV with internet connection.  Part of its characteristics, is that I should be a

  • HP cooling fan

    OK, so I've had my laptop for less than two years. Just before the year mark the cooking fan came out and I had to replace. Now, it's been 10 months and she will or is already out again. What could cause this problem and it is less than one year sinc