Different query behaviour (index or no index use) between sql and pl/sql

Hi All,
I have a query inside a cursor in a procedure, let's say:
cursor c_emp (b_dept_no in number)
is
select *
from emp
where dept_no = b_dep_no;
There is an non unique index on dept_no.
In this procedure i first loop through another cursor which gets the dept_no and with this dept_no i go into a for loop for the c_emp cursor.
When i run this procedure i see that the explain plan of above query gives me a Full table Scan on EMP, eventhough there is a index on dept_no and there are 1.3 million records in the em table. When i take the above query and explain it seperately, it uses the index on dept_no.
I have rebuild/analyzed the tables and indexes, nothing seems to work. Even hints in the procedure cursor are not helping at all.
I'm using Oracle Database 10.2.0.1.0 and have never seen such behaviour before.
Anyone an idea what is going on here?
Kind regards,
Dave

Hoi Rob,
it's like i have three tables. The first i have to get data from for my output, then for every record of table one there are one or more records in table 2 and table 3.
I had to create a xml file and it looks like this:
<Table1 Record 1>
<Name>...</Name>
etc...
<Table2 Record 1>
</Table2 Record 1>
<Table2 Record 2>
</Table2 Record 2>
<Table3 Record 1>
</Table3 Record 1>
<Table3 Record 2>
</Table3 Record 2>
<Table1 Record 2>
etc.etc.etc.
So that's why i programmed:
for r_1 in c_table1 loop
for r_2 in c_table2(r_1.dept_no) loop
end loop;
for r_3 in c_table3(r_1.dept_no) loop
end loop;
end loop;
And when i look at the first record,
it has 2 records in table2 en 16 records in table3. So nothing huge.
For now i'm unable to trace the session. I will try to post the tkprof later.
Kind regards,
Dave

Similar Messages

  • Performance comparison between using sql and pl/sql for same purpose

    Hi All,
    I have to do some huge inserts into a table from some other tables. I have 2 option:
    Option 1
    ======
    a. Declare a cusor for a query involving all source tables, this will return the data to be populated into target
    b. Use a cursor for loop to loop through all the records in the cursor
    c. for each iteration of the loop, populate target columns, do any calculations/function calls required to populate derived columns, and then insert the resulting record into target table
    Option 2
    ======
    Just write a big single "Insert Into ..... Select ..." statement, doing alll calculations/funtion calls in the select statement generating the source data.
    Now my question is ; which option is fast? and why. This operation is performace critical so I need the option which will run faster. Can anybody help???
    Thanks in Advance.

    user9314072 wrote:
    while the above comments are vaild, you should concider maintainability in you code. Even if you can write the sql it might be the code becomes complex making tuning very dificult, and derade performance.Beg to differ on that. Regardless of complexity of code, SQL is always faster than PL/SQL when dealing with SQL data. The reason for that is that PL/SQL still needs to use SQL anyway for row retrieval, and in addition it needs to copy row data from the buffer cache into the PL/SQL PGA. This is an overhead that does not exist in SQL.
    So if you are processing a 100 million rows with a complex 100 line SQL statement, versus a 100 million rows 100 line PL/SQL procedure, SQL will always be faster.
    It is a trade off, my experiance is large SQL's 100's lines long become hard to manage. You need to ask yourself why there are 100's of line of SQL. This points to an underlying problem. A flaky data model is very likely the cause. Or not using SQL correctly. Many times a 100 line SQL can be changed to a 10 liner by introducing different logic that solves the exact same problem easier and faster (e.g. using analytical SQL, thinking "+out-of-the-box+").
    Also, 100's of line of SQL points to a performance issue always. And it does not matter where you move this code logic to PL/SQL or Java or elsewhere, the performance problem will remain. Moving the problem from SQL to PL/SQL or Java does not reduce the number of rows to process, or make a significant change in the number of CPU instructions to be executed. And there's the above overhead mentioned - pulling SQL data into a client memory segment for processing (an overhead that does not exist using SQL).
    So how do you address this then? Assuming the data model is correct, then there are 2 primary methods to address the 100's of SQL lines and its associated performance problem.
    Modularise the SQL. Make the 100's of lines easier to maintain and understand. This can be done using VIEWS and the SQL WITH clause.
    As for the associated performance issue - materialised views comes to mind as an excellent method to address this type of problem.
    my advice is keep things simple, because soon or later you will need to change the code.I'm all for that - but introducing more moving parts like PL/SQL or Java and ref cursors and bulk fetching and so on.. how does that reduce complexity?
    SQL is the first and best place to solve row crunching problems. Do not be fooled into thinking that you can achieve that same performance using PL/SQL or Java.

  • What should I use  between JSE and JEE?

    Is it true that JSE can do only certain level, but JEE can do the same with JSE and specially beyound of JSE.? If i want to develop a web application, what should i install to my computer between JSE and JEE or i have to install its both?

    hi
    you dont get all the features of j2se when you have j2ee with you. they are 2 different things.
    j2ee mostly deals with things which are required for a enterprise application building which include EJBs, Servlets, JSPs etc. while the J2SE is more useful for application developement (using Swing e.g). this is only a crude differentiation.
    the choice betweeen the two depends on your requirement. e.g. if you are developing a web application, you will go for J2EE and proceed using the components available there.
    if you specify your requirements, then we can discuss the details may be.
    Parag

  • Differences in "storage used" between iPad and iTunes

    I have an iPad Mini 2 and there a differences between the stated "storage used" between the iPad and iTunes.
    Looking in the general settings "Storage" it states I have used 113GB and available is 413MB.
    Looking on iTunes, when the iPad is connected, it states I have 67.20GB free.
    Which is correct and what causes the problem?
    How is it fixed if it is because the iPad has a fault?
    Many thanks.

    It is now a couple of weeks and noticed the discrepancy occurring again.  I did not want to go through the above process again because it took about 4 hours to get my iPad up, running again and normal.
    Again, there was a difference in memory by about 20GB.
    This time it tried something different.
    1) Went into General settings on iPad and managed memory.  From here I removed all films and TV episodes.  Now Video memory was zero.
    2) Switched off WiFi.  When I opened the Video app, I noticed a pile of films and TV episodes showing, even though they had the cloud icon.  They could even be watched.  I deleted these films/episodes.
    3) Viewed the iPad memory using iTunes on laptop and compared to iPad general settings usage (video memory negligible).  Both numbers pretty much spot on.
    My musings - I can only assume that the iPad does not properly delete films/episodes that I had previously watched.  It is evidently holding on to the video, even though I had deleted them and they were not showing in general settings.  Though it is a hassle, I at least now how to find where the "lost" memory is and how to reclaim it.

  • What is better and fast to use between decode and case

    Hi friends,
    i wanted to know what is better to use decode or case in sql,which gives faster result.
    thks
    sonal....

    Here's a very simple timing comparison. This table (actually it's a partition) has a little over 1 million rows.
    As you can see, the timing difference is trivial. (I ran an earlier query to fetch the blocks from disk).
    SQL> select sum(decode(balloon_flag
      2                   ,'Y',1
      3                   ,0
      4                   )
      5            ) bal_count
      6  from   prod.loan_master
      7  where  report_date = to_date('31-DEC-2005');
               BAL_COUNT
                    9036
    Elapsed: 00:00:07.65
    SQL> select sum(case balloon_flag
      2                  when 'Y' then 1
      3                  else  0
      4             end
      5            ) bal_count
      6  from   prod.loan_master
      7  where  report_date = to_date('31-DEC-2005');
               BAL_COUNT
                    9036
    Elapsed: 00:00:07.68
    SQL> select sum(case
      2                  when balloon_flag = 'Y' then 1
      3                  else  0
      4             end
      5            ) bal_count
      6  from   prod.loan_master
      7  where  report_date = to_date('31-DEC-2005');
               BAL_COUNT
                    9036
    Elapsed: 00:00:07.46

  • How to specify a cipher suit used between plugin and weblogic server?

    I install Weblogic8.1 SP3 which supports for strong cipher suits, and config an apache 2.50 server as an front end.
    I config appache to use 2 way SSL with browser and wls one way SSL with apache plugin. Then config apache to forward client certs to WLS. now the problem is, I can see that the SSL connection between browser and apache uses a strong cipher suit('SSL_RSA_WITH_RC4_128_MD5'), but the ssl connection bwtween apache plugin and WLS uses a weak cipher suit('SSL_RSA_EXPORT_WITH_RC4_40_MD5'), with the SnoopServlet, although I use the mod_wl128_20.so module. How can I increase the cipher strength of SSL between WLS and it's apache plugin?
    Thanks in advance.
    Best
    Regards
    Jean

    Hello Gunaseelan,
    This is not possible because WLS 6.1 needs a config.xml file, exactly this
    name, to start.
    What you can do is to define a recovery domain, called myrecovery_domain for
    instance, and put the config_recovery.xml, renamed "config.xml".
    Hope this helps,
    Ludovic.
    Developer Relations Engineer
    BEA Support.
    "Gunaseelan Venkateswaran" <[email protected]> a écrit dans le message
    news: 3cd6a324$[email protected]..
    >
    Hi,
    I have 2 weblogic startup scripts (startWebLogic.sh and
    startWebLogic_recovery.sh) for the same domain.
    startWebLogic.sh uses config.xml file.
    I would like to use config_recovery.xml as the configuration file forstartWebLogic_recovery.sh
    >
    >
    How would I do this ?
    I am using WebLogic Server 6.1 on SunOS 5.8 / HP-UX 11.0.
    Appreciate any help.
    Regards
    Gunaseelan Venkateswaran

  • USB flash drive use between PC and MAC

    I have a usb flash drive that has files on it previously created using a PC.  It contains excel, word and powerpoint files.  I have Office for Mac and put some of  the files on the mac edited them and then tried to save them or move them back onto the drive, but cannot. I get a variety of messages including the disk is full and it is not and that it is write protected, but USB flash drives cannot be write protected.  Are usb drives portable between mac and PCs?

    hey man.
    Save the files on the jump drive to a folder on the mac.  Keep it in a good spot cuz your going to need it.
    Open disk utilities on the mac.
    click on the correct usb drive in the screen, and then click erase.  U will have formatting options in a drop down tab, pick "FAT" or "FAT 32" which it is, name it and hit erase.
    This will reformat the drive to a windows usable file format, and the mac will work with it no problem.
    Once reformat is complete close disk util. and open the mounted USB drive, found on the desktop and drag the folder you had created to it and your good to go.
    windows should have no problem reading it at all now.
    hope this helps

  • Different Result for SQL and PL/SQL query..need a bit of help

    If i just run:
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';
    It works great.
    If I run
    BEGIN
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';
    END
    I get the following error.
    ORA-04052: error occurred when looking up remote object [email protected]
    ORA-00604: error occurred at recursive SQL level 3
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-488: invalid variable declaration: object 'NUMBER' must be a type or subtype
    ORA-02063: preceding 2 lines from SMGLINK

    Hi,
    Whenever you have a problem, post a complete test script that people can run to re-create the problem and test their ideas. Include CREATE TABLE and INSERT statements for any or your own tables needed.
    Post the results you want from that sample data.
    Always say which version of Oracle you're using.
    bostonmacosx wrote:
    If i just run:
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';If OPEN_TIME is a DATE, then don't try to compare it to a string, such as '1/1/2011'. (This is not related to the present problem, only a future one.)
    It works great.
    If I run
    BEGIN
    SELECT COUNT(*) from DB where (CLOSE_TIME-OPEN_TIME<5) and (CLOSE_TIME-OPEN_TIME>=1) and OPEN_TIME>'1/1/2011';
    END
    I get the following error.
    ORA-04052: error occurred when looking up remote object [email protected]
    ORA-00604: error occurred at recursive SQL level 3
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-488: invalid variable declaration: object 'NUMBER' must be a type or subtype
    ORA-02063: preceding 2 lines from SMGLINKI would expect a different error "PLS_00428: an INTO clause is expected".

  • I am getting very different graphical results from mp4 video files using iOS5.1 and iOS6. The OS6 is 1/3 the size of the iOS5?

    We are converting some Flash online courses over to html5/mp4. Under the iOS5.1 everything looks great. Viewing the same course under iOS6, the video window is about 1/3 the height. We have tested this on multiple IPad devices and get the same results. Suggestions? Thanks.

    We are converting some Flash online courses over to html5/mp4. Under the iOS5.1 everything looks great. Viewing the same course under iOS6, the video window is about 1/3 the height. We have tested this on multiple IPad devices and get the same results. Suggestions? Thanks.

  • Strange behavior when searching a phrase using reg exp and dynamic sql

    Hi,
    I have a strange issue while using dynamic sql for an apex page. I have a requirement to search a string in the database column which is entered by user on a page item. The search process should search the whole phrase only.
    I have a query generated dynamically in the back end and use it in a cursor in the stored procedure
      SELECT t.group_cn , t.group_desc, t.group_type, t.partner_organization_id, t.partner_organization
      FROM vr_idm_group t WHERE regexp_like(t.group_desc,'(^|\W)HR Selection & Assignment(\W|$)', 'i')The pl sql code with the dynamic sql statements are below.
       IF p_search_process NOT in ('PARTNER') THEN
          OPEN v_cursor FOR v_sql;
       ELSE
          OPEN v_cursor FOR v_sql USING p_search_id;
       END IF;
       LOOP
          FETCH v_cursor INTo v_obj.group_cn, v_obj.group_desc, v_obj.group_type, v_obj.partner_organization_id,
             v_obj.partner_organization, v_obj.match_count;
          EXIT WHEN v_cursor%NOTFOUND ;
          v_search_array.extend;
          v_search_array(v_search_array.last) := v_obj;
          dbms_output.put_line(v_sql);
       END LOOP;The search works fine if the search string does not contain any special character like &,- etc.
    However, if the search string contains any special character, it does not return any thing. This strange issue happens only if I call the procedure from the apex page and the search string contains a special character. (please note that the procedure works fine even from apex if the string does not have a special character). When I debugged this, found that, the cursor does not fetch any rows (it is supposed to fetch two rows) for unknown reason. When I run the query separately, it returns the two rows (in which the column group_desc contains the search string "HR Selection & Assignment") as desired. Also, when I test the procedure in the back end (PLSQL developer), it works fine.
    Any idea, what is causing this strange behaviour?
    Advance thanks.
    Regards,
    Natarajan

    i don't see anything about a dataProvider.  you're assigning a source for a scrollpane.  scrollpane's don't have a dataProvider property.
    anyway, other than arrayRun always being false when that last if-statement executes, what's the problem?  doesn't that movieclip display when that 2nd branch of the last if-statement executes (assuming instance is defined correctly etc)?

  • Insert into using a select and dynamic sql

    Hi,
    I've got hopefully easy question. I have a procedure that updates 3 tables with 3 different update statements. The procedure goes through and updates through ranges I pass in. I am hoping to create another table which will pass in those updates as an insert statement and append the data on to the existing data.
    I am thinking of using dynamic sql, but I am sure there is an easy way to do it using PL/SQL as well. I have pasted the procedure below, and what I'm thinking would be a good way to do it. Below I have pasted my procedure and the bottom is the insert statement I want to use. I am faily sure I can do it using dynamic SQL, but I am not familiar with the syntax.
    CREATE OR REPLACE PROCEDURE ACTIVATE_PHONE_CARDS (min_login in VARCHAR2, max_login in VARCHAR2, vperc in VARCHAR2) IS
    BEGIN
    UPDATE service_t SET status = 10100
    WHERE poid_id0 in
    (SELECT poid_id0 FROM service_t
    WHERE poid_type='/service/telephony'
    AND login >= min_login AND login <= max_login);
    DBMS_OUTPUT.put_line( 'Service Status:' || sql%rowcount);
    UPDATE account_t SET status = 10100
    WHERE poid_id0 IN
    (SELECT account_obj_id0 FROM service_t
    WHERE poid_type = '/service/telephony'
    AND login >= min_login AND login <= max_login);
    DBMS_OUTPUT.put_line( 'Account Status:' || sql%rowcount);
    UPDATE account_nameinfo_t SET title=Initcap(vperc)
    WHERE obj_id0 IN
    (SELECT account_obj_id0 FROM service_t
    WHERE poid_type='/service/telephony'
    AND login >=min_login AND login <= max_login);
    DBMS_OUTPUT.put_line('Job Title:' || sql%rowcount);
    INSERT INTO phone_card_activation values which = 'select a.status, s.status, s.login, to_char(d.sysdate,DD-MON-YYYY), ani.title
    from account_t a, service_t s, account_nameinfo_t ani, dual d
    where service_t.login between service_t.min_login and service_t.max_login
    and ani.for_key=a.pri_key
    and s.for_key=a.pri_key;'
    END;
    Thanks for any advice, and have a good weekend.
    Geordie

    Correct my if I am wrong but aren't these equal?
    UPDATE service_t SET status = 10100
    WHERE poid_id0 in
    (SELECT poid_id0 FROM service_t
    WHERE poid_type='/service/telephony'
    AND login >= min_login AND login <= max_login);
    (update all the records where there id is in the sub-query that meet the WHERE Clause)
    AND
    UPDATE service_t SET status = 10100
    WHERE poid_type='/service/telephony'
    AND login >= min_login AND login <= max_login);
    (update all the records that meet the WHERE Clause)
    This should equate to the same record set, in which case the second update would be quicker without the sub-query.

  • I have multiple apple devices mainly used between me and my wife , my question is that can i have two sets of contacts backed up to icloud one for her devices and one for my devices using the same itunes account

    i have two sets of devices one ipad, iphone and mac which i use and one iphone ipad and mac which my wife uses
    now is it possible to have two sets of contacts and calendar synchronised for her devices and one for my devices using the same icloud account
    i dont want a separate itunes account as we use the same music books and apps to be automatically downloaded which is very convenient
    please guide

    You can set up different iCloud accounts on each device using different Apple IDs (to keep your mail, calendars, contacts, etc. separated), and still share the same iTunes account (in Settings>Store on your device).  There is no requirement that you use the same Apple ID for purchases and for iCloud.

  • Different results of same calculation between SQL and PL/SQL

    This SQL statement:
    select 1074 * (4 / 48) from dual;Gives the result 89.5.
    However this PL/SQL block
    declare
        tmp     NUMBER;
    begin
        SELECT 1074 * (4 / 48) into tmp from dual;
        dbms_output.put_line('Result '||tmp);
    end;Gives a different result:
    Result 89.49999999999999999999999999999999999996
    If I change and give my variable tmp a precision and scale, say (38,36) then the result is 89.5.
    Edit. I have done this on both 10g (10.2.0.4.0) and 11g (11.1.0.7.0) with the same result in both.
    Edited by: kendenny on Jul 9, 2010 10:19 AM for additional information

    What's your current NUMWIDTH value in SQL*Plus (I'm assuming you are using that as your tool)?
    SQL> set numwidth 50
    SQL> select 1074 * (4 / 48) from dual;
                                           1074*(4/48)
             89.49999999999999999999999999999999999996

  • Drive use between MAcs and PCs

    Hello,
    I hope this is the right place for this query... I would like to extract a hard drive from a Sony laptop that is one year old (just out of warrantee and Sony won't fix it!) and hook it up to my MACBook or MAC Pro to delete data or reformat to destroy sensitive data before giving it to some student who think they can fix the thing... Can I access the data with my MAC and reformat it to whatever format (MAC or other does not matter as long as the data is gone)?
    Thanks for help with this... Floor
    P.S. I tried to access USB drives with my work Windows based laptop and failed (could not see it in the Explorer while I could eject it - failing to would bring up the message of possible data corruption.. Is that normal? Or are these drives interchangeable with the latest windows PCs (my work laptop uses Windows 2000, yes I know Barney Flintstone probably owned it one day).

    If the drive is formatted Windows NT, your Mac will be able to read the files on the drive, but you will not be able to change the files in any way, including dragging them to the trash. To delete the files, reformat the drive using Disk Utility. Be sure to click on the security options button and select "Zero Out Data." Otherwise, someone will still be able to recover your data from the drive.

  • 1 hd with 2 file formats for use between mac and windows?

    Think this is the right forum...
    I want to instal a program onto an external hard drive for use on both mac and windows. The program supports both mac and windows.
    My plan is to get an external hd and partition it in half. One half i will format mac os extended and the other i will format ntfs. I'll instal the mac version on the mac partition and the windows version on the ntfs partition.
    This should work i'm thinking, yes? I.e. when i plug it into windows it'll run the windows installation no problem and when i plug it into the mac it'll run the mac installation no problem?
    Thanks.

    An easier solution might be to just connect the drive to a Windows PC and format it as FAT32. Both Windows (98 and higher) as well as Mac allow full read/write access to FAT32 formatted drives. No need to download any drivers, etc. It just works.
    Yes, this solution is not perfect, but none are. The free NTFS drivers for Mac are not most efficient drivers for speed/performance, the HFS+ drivers for Windows are not cheap, and have their own performance issues, and FAT32 has the limit of file sizes over 2GB (or is it 4GB now?) not supported. No one solution is perfect, but for the many one is better than the others, but it all depends upon their circumstances which is "better".

Maybe you are looking for

  • Podcasts won't open with IOS7

    I updated my iPhone 4s with iOS 7 and now I can't get the podcast app to open. It just goes back to the home screen. I've tried syncing it with iTunes, checking my settings, etc. but nothing. Help!

  • Time machine has deleted all old backups -  I think

    Dear All, Time machine failed tonight. It said there wasn't enough disk space (2TB external drive). I went into time machine and all the backups bar one from this morning are gone. One thing that did happen today was that I ran disk utility on HD1 an

  • Reduce image size in pages by cropping ??

    Hello, I created a pages document with a lot of masked images in it. the resulting pdf file is massive. As described in the Pages manual, I tried the reduce the image file size (format menu) and the document file size (file menu). But instead of redu

  • Please help me, I recently had to reset my computer and lost my entire hard

    Hard drive. AFter getting the computer to work again, I reinstalled my Itunes software. I then wanted to transfer my music from my IPOD to my computer. I followed the step by step support instructions and after it told me to click "Consolidate librar

  • BW is a part of My SAP Applications

    I need what are the my SAP Components..can any body help me please... BI is under my SAP?