Number of Execution of Sub-Query

Hi,
Let suppose we have a SQL which has a sub-query in the filter NOT IN clause as shown below. I wish to know that whether for each record from Table_1 (T1),
the inner/filter SQL will execute
or
It will execute only once for that session (All the records from T1).
Meaning: Let suppose Table_1 has 5 Million records. So whether the filter/sub-query will be executed 5 Million times by Oracle Engine or It will be executed only once.
SQL:
SELECT T1.C1, T1.C2, T2.C3 FROM Table_1 T1
INNER JOIN
Table_2 T2
ON T1.C1=T2.C1
WHERE T1.C2 = 0 AND
T1.C4 NOT IN(SELECT DISTINCT COLUMN_12 FROM TABLE_3 WHERE COLUMN_13 = 'VALUE');
Best Regards,
Mayur

It depends on the execution plan. NOT IN can be converted to NOT EXISTS, it can be converted to an ANTI-JOIN.
If it's converted to a hash (or merge) ANTI-JOIN the subquery is (effectively) executed once, if it's converted to a nested loop anti-join it's (effectively) executed once per row in the driving rowsource. If it's converted to a NOT EXISTS filter subquery it may be executed as much as once per row in the driving row source, it may be executed as little as once per distinct value in the driving row source. (See http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/ for an example of the FILTER subquery count
Regards
Jonathan Lewis

Similar Messages

  • The issue with using the multiple columns sub-query in WHERE clause

    Hi All,
    my database version is 10.2.
    the problem i am trying to deal with is that when I use multiple column sub-query in the WHERE clause of the SELECT statement, the actual row number returned from the sub-query is different from the whole statement.
    And what I found is that, whenever there is NULL in any of those columns returned from the SUB-QUERY, the outer query will just return NULL for that whole row.
    Here is an example:
    select empno, ename, job, mgr, hiredate, sal, deptno from EMP
    intersect
    select empno, ename, job,  mgr, hiredate, sal, deptno from t;
    7782     CLARK     MANAGER     7839     09-JUN-81     2450     10
    7839     KING     PRESIDENT  NULL  17-NOV-81     5000     10
    7934     MILLER     CLERK     7782     23-JAN-82     1300     10
    select * from EMP where (EMPNO, ENAME, job, MGR, HIREDATE, SAL, DEPTNO) in (
    select empno, ename, job, mgr, hiredate, sal, deptno from EMP
    intersect
    select empno, ename, job,  mgr, hiredate, sal, deptno from t);
    7782     CLARK     MANAGER     7839     09-JUN-81     2450          10     
    7934     MILLER     CLERK     7782     23-JAN-82     1300          10     If I specifically deal with the NULL situations for the columns which might return NULL, I can get the result right.
    select * from EMP where (EMPNO, ENAME, job, NVL(MGR,-1), HIREDATE, SAL, DEPTNO) in (
    select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from EMP
    intersect
    select empno, ename, job,  nvl(mgr,-1), hiredate, sal, deptno from t);
    7782     CLARK     MANAGER     7839     09-JUN-81     2450          10     
    7839     KING     PRESIDENT  null   17-NOV-81     5000          10     
    7934     MILLER     CLERK     7782     23-JAN-82     1300          10     the problem is that, I feel this is a very lame way of handling it.
    So, I wonder or am asking if there is any better or standard way to do it?
    any help would be highly appreciated.
    Thanks

    Hi,
    As you discovered, INTERSECT treats NULL as a value, but IN does not.
    What you did with NVL is one way to handle the situation. If there was a chance that any of the columns could be NULL, then you might prefer something like this:
    select      *
    from      EMP
    where      ( EMPNO      || '~' ||
           ENAME      || '~' ||
           job           || '~' ||
           MGR           || '~' ||
           TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
                    || '~' ||
           SAL           || '~' ||
           DEPTNO
         ) in (
              select  EMPNO      || '~' ||
                     ENAME      || '~' ||
                   job     || '~' ||
                   MGR     || '~' ||
                   TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')               
                        || '~' ||
                   SAL      || '~' ||
                   DEPTNO
              from     emp
             intersect
              select  EMPNO      || '~' ||
                     ENAME      || '~' ||
                   job     || '~' ||
                   MGR     || '~' ||
                   TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')               
                        || '~' ||
                   SAL      || '~' ||
                   DEPTNO
              from      t
             );This assumes that you can identify some string (I used '~') that never occurs in the strings in these tables.
    This is implicitly converting the NUMBERs. That's usually not a good thing to do. but explicitly converting them would make this even more tedious.
    You should explicitly convert any DATEs to strings, however. Depending on your default format, and your data, you might get away with implicit conversions even for DATEs, but don't bet on it.
    If you had to do this often, you might consider writing a user-defined function:
    delimited_string (empno, ename, job, mgr, hiredate, sal, deptno) would return a string like
    '7839~KING~PRESIDENT~~17-NOV-1981~5000~10'
    This will make the coding easier, but beware: it will make the execution slower.

  • Finding number of working days during query execution

    Hi ,
    We have a requirement to calculate number of working days during query execution. In the cube we got "received date", this will be used as a variable in the query. Based on the received date value entered, query needs to display number of products received from past 1, 2,3,4 days (working days should include weekends or public holidays).
    1day     2 days     3 days     4 days   5 days 
    10         12            20            15          20
    to me it appears as I need to create virtual key figures.
    Regards,
    Ramz

    Hi ramesh,
    First try to create formula variables for start data and end date to calculate the no of working days.
    Create a Variable ZSTDT --of type replacement path.
    Type of Variable = Formula
    Variable Name = ZSTDT
    Characteristic = <info object>
    For Intervals Use = Select From Value
    Offset Start = 0000 Offset Length = 0000
    Replacement var with : key
    use the same steps to create one more formula variable to get end date.
    Now create a formula to get the No of days.
    once after getting no of days you can create buckets as per your need.
    for more info check the below links
    http://www.sd-solutions.com/SAP-HCM-BW-Replacement-Path-Variables.html
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/30f15839-0cf1-2b10-c6a7-ebe68cc87cdc?quicklink=index&overridelayout=true

  • Query to know number of executions of one day

    Hi,
    i need a query to get number of executions of the sql per day

    What database version ?
    You mean there is one sql statement you want to check daily executions ? Does it have the same sql ID each time ? If so then you could select from v$sql / v$sqlarea every 24 hours and compare counts from the previous runtime.
    Are you collecting statspack and awr snaps ? If so then you may be able to run a report to view executions in 24 hour periods.

  • 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

  • Can someone please help me with a sub query question?

    I need to list a 3rd party contract and then a list of students who belong to that contract.
    On the students segment of the listing I need to show students with student id, name, total credit hours,
    total amount spent on tuition, total amount spent on books and total amount spent on misc.
    This code has a query for the contract information and I get that just fine.
    Then it has a query that gives me total credit hours and that works fine
    then it has a query that gives me total amount spent on tuition and that works fine
    but
    when I add the next query to get total amount spent on books I get only the information for the contract, I don't get student stuff anymore.
    I would really appreciate any guidance that you could give.
    Thanks in advance, Bob Hohulski
    DECLARE
    l_conn utl_TCP.connection;
    v_filehandle utl_file.file_type;
    v_output varchar2(1000);
    v_contract_id varchar2(9);
    v_contract_addr1 varchar2(30);
    v_contract_addr2 varchar2(30);
    v_contract_city varchar2(20);
    v_contract_stat varchar2(03);
    v_contract_zip varchar2(10);
    v_contract_name varchar2(60);
    v_student_id varchar2(09);
    v_student_first_name varchar2(15);
    v_student_mid_name varchar2(15);
    v_student_last_name varchar2(60);
    v_last_out varchar2(20);
    v_student_detail_code varchar2(04);
    v_student_amount number(12,2);
    v_student_ref_number varchar2(09);
    v_credit_hrs number(7,2);
    v_tuition_amount number(12,2);
    v_books_amount number(12,2);
    v_misc_amount number(12,2);
    v_total_for_student number(12,2);
    v_current_student varchar2(09);
    v_sftregs_pidm varchar2(09);
    v_tbraccd_pidm varchar2(09);
    CURSOR c_sel_contract IS
    SELECT DISTINCT spriden_id, spriden_last_name,
    spraddr_street_line1, spraddr_street_line2,
    spraddr_city, spraddr_stat_code, spraddr_zip
    FROM spriden, spraddr
    -- WHERE spriden_id = '&Enter_Id'
    where spriden_id = 'T10474666'
    AND spriden_pidm = spraddr_pidm
    AND SPRIDEN_CHANGE_IND IS NULL;
    CURSOR c_sel_student IS
    SELECT DISTINCT spriden_id, spriden_first_name, spriden_mi, spriden_last_name,
    sftregs_credit_hr,
    tbraccd_amount,
    sftregs_pidm,
    tbraccd_pidm
    FROM spriden, tbraccd, tbbcstu, sftregs
    WHERE 559220 = tbbcstu_contract_pidm
    AND spriden_pidm = tbraccd_pidm
    AND spriden_pidm = tbbcstu_stu_pidm
    AND spriden_pidm = sftregs_pidm
    AND (sftregs_pidm, sftregs_credit_hr) IN
    (SELECT DISTINCT sftregs_pidm, SUM(sftregs_credit_hr)
    FROM sftregs, tbbcstu, spriden
    WHERE sftregs_term_code = '201010'
    AND sftregs_pidm = tbbcstu_stu_pidm
    AND sftregs_pidm = spriden_pidm
    GROUP BY sftregs_pidm)
    AND (tbraccd_pidm, tbraccd_amount) IN
    (SELECT DISTINCT tbraccd_pidm, SUM(tbraccd_amount)
    -- tuition
    FROM tbraccd, tbbcstu, spriden
    WHERE tbraccd_term_code = '201010'
    AND (tbraccd_detail_code = 'TU01' OR
    tbraccd_detail_code = 'TU02' OR
    tbraccd_detail_code = 'TU03' OR
    tbraccd_detail_code = 'TU04')
    AND tbraccd_pidm = tbbcstu_stu_pidm
    AND tbraccd_pidm = spriden_pidm
    GROUP BY tbraccd_pidm)
    --this code works up to this point
    --when I add the next query I get nothing
    AND (tbraccd_pidm, tbraccd_amount) IN
    (SELECT tbraccd_pidm, SUM(tbraccd_amount)
    books
    FROM tbraccd, tbbcstu
    WHERE tbraccd_term_code = '201010'
    AND (tbraccd_detail_code = 'BKSU' OR
    tbraccd_detail_code = 'BKCH')
    AND tbraccd_pidm = tbbcstu_stu_pidm
    GROUP BY tbraccd_pidm, tbraccd_amount)
    --AND (tbraccd_pidm, tbraccd_amount) IN
    -- (SELECT tbraccd_pidm, SUM(tbraccd_amount)
    -- misc
    -- FROM tbraccd, tbbcstu
    -- WHERE tbraccd_term_code = '201010'
    -- AND tbraccd_pidm = tbbcstu_stu_pidm
    -- AND (tbraccd_detail_code = 'AUNA' OR
    -- tbraccd_detail_code = 'OTPB')
    -- GROUP BY tbraccd_pidm, tbraccd_amount)
    --ORDER BY tbraccd_pidm, spriden_first_name, spriden_mi, spriden_last_name,
    -- tbbcstu_sponsor_ref_number, sftregs_credit_hr;
    ORDER BY tbraccd_pidm;
    BEGIN
    v_filehandle := utl_file.fopen(location => 'UTLFILE_MISAP9',
    filename => 'ban_matrix.dat',
    open_mode => 'w',
    max_linesize => 32767);
    OPEN c_sel_contract;
    LOOP
    DBMS_OUTPUT.PUT_LINE('looping');
    FETCH c_sel_contract INTO v_contract_id, v_contract_name,
    v_contract_addr1, v_contract_addr2,
    v_contract_city, v_contract_stat,
    v_contract_zip;
    EXIT WHEN c_sel_contract%NOTFOUND;
    v_output :=
    nvl(rpad(v_contract_id,9),rpad(' ',9)) ||
    ' ' ||
    nvl(rpad(v_contract_name,60),rpad(' ',60));
    utl_file.put_line(v_filehandle,v_output);
    v_output :=
    nvl(rpad(v_contract_addr1, 30),rpad(' ',30)) ||
    ' ' ||
    nvl(rpad(v_contract_addr2, 30),rpad(' ',30));
    utl_file.put_line(v_filehandle,v_output);
    v_output :=
    nvl(rpad(v_contract_city, 20), rpad(' ',20)) ||
    ' ' ||
    nvl(rpad(v_contract_stat, 3), rpad(' ',3)) ||
    ' ' ||
    nvl(rpad(v_contract_zip, 10), rpad(' ',10));
    utl_file.put_line(v_filehandle,v_output);
    utl_file.new_line(v_filehandle);
    OPEN c_sel_student;
    LOOP
    FETCH c_sel_student into v_student_id, v_student_first_name, v_student_mid_name,
    v_student_last_name,
    v_credit_hrs,
    v_tuition_amount,
    v_sftregs_pidm,
    v_tbraccd_pidm;
    -- v_books_amount, v_misc_amount;
    EXIT WHEN c_sel_student%NOTFOUND;
    v_last_out := substr(v_student_last_name, 1, 20);
    v_output :=
    nvl(rpad(v_student_id, 09),rpad(' ',09)) ||
    ' ' ||
    nvl(rpad(v_student_first_name, 15),rpad(' ',15)) ||
    nvl(rpad(v_student_mid_name, 15),rpad(' ',15)) ||
    nvl(rpad(v_last_out, 20),rpad(' ',20)) ||
    ' ' ||
    nvl(rpad(v_student_ref_number, 09),rpad(' ',09)) ||
    ' ' ||
    v_credit_hrs ||
    ' ' ||
    v_tuition_amount ||
    -- v_books_amount ||
    -- ' ' ||
    -- v_misc_amount;
    utl_file.put_line(v_filehandle,v_output);
    END LOOP;
    END LOOP;
    --EXCEPTION
    --WHEN OTHERS THEN
    -- DECLARE
    -- err_msg VARCHAR2(100);
    -- BEGIN
    -- err_msg := 'ERR- '||SUBSTR(SQLERRM, 1,100);
    -- - utl_file.put_line(v_filehandle,err_msg);
    --END;
    utl_file.fclose(v_filehandle);
    CLOSE c_sel_contract;
    CLOSE c_sel_student;
    --END AR_MATRIX_PROC;
    END;

    run this original query
    SELECT DISTINCT spriden_id,
            spriden_first_name,
            spriden_mi,
            spriden_last_name,
            sftregs_credit_hr,
            tbraccd_amount,
            sftregs_pidm,
            tbraccd_pidm
       FROM spriden, tbraccd, tbbcstu, sftregs
    WHERE 559220 = tbbcstu_contract_pidm
       AND spriden_pidm = tbraccd_pidm
       AND spriden_pidm = tbbcstu_stu_pidm
       AND spriden_pidm = sftregs_pidm
       AND (sftregs_pidm, sftregs_credit_hr) IN (SELECT DISTINCT sftregs_pidm, SUM(sftregs_credit_hr)
                                                   FROM sftregs, tbbcstu, spriden
                                                  WHERE sftregs_term_code = '201010'
                                                    AND sftregs_pidm = tbbcstu_stu_pidm
                                                    AND sftregs_pidm = spriden_pidm
                                                 GROUP BY sftregs_pidm)
       AND (tbraccd_pidm, tbraccd_amount) IN (SELECT DISTINCT tbraccd_pidm, SUM(tbraccd_amount)
                                              -- tuition
                                                FROM tbraccd, tbbcstu, spriden
                                               WHERE tbraccd_term_code = '201010'
                                                 AND (tbraccd_detail_code = 'TU01' OR
                                                      tbraccd_detail_code = 'TU02' OR
                                                      tbraccd_detail_code = 'TU03' OR
                                                      tbraccd_detail_code = 'TU04')
                                                 AND tbraccd_pidm = tbbcstu_stu_pidm
                                                 AND tbraccd_pidm = spriden_pidm
                                               GROUP BY tbraccd_pidm)
       AND (tbraccd_pidm, tbraccd_amount) IN (SELECT tbraccd_pidm, SUM(tbraccd_amount) books
                                                FROM tbraccd, tbbcstu
                                               WHERE tbraccd_term_code = '201010'
                                                 AND (tbraccd_detail_code = 'BKSU' OR
                                                      tbraccd_detail_code = 'BKCH')
                                                 AND tbraccd_pidm = tbbcstu_stu_pidm
                                              GROUP BY tbraccd_pidm, tbraccd_amount)
    ORDER BY tbraccd_pidm;then run this sub-query:
    SELECT tbraccd_pidm, SUM(tbraccd_amount) books
       FROM tbraccd, tbbcstu
      WHERE tbraccd_term_code = '201010'
        AND (tbraccd_detail_code = 'BKSU' OR
             tbraccd_detail_code = 'BKCH')
       AND tbraccd_pidm = tbbcstu_stu_pidm
    GROUP BY tbraccd_pidm, tbraccd_amount)see if you have a matching tbraccd_pidm and tbraccd_amount between the two results.

  • Doubt in sub-query

    I have a doubt with the use of sub-queries. I am using a query like as below & it is giving me expected result:-
    SELECT ISS.item_type_id,count(1) + (select sum(invoiced_qty) from ppbs_invoice_detail where
    trunc(created_date) between '01-jul-05' and '04-jul-05' and item_type_id=ISS.item_type_id) qty
    FROM ppbs_INV_SIM_SERIAL ISS
    WHERE INSTR('ROAAIT',STATUS)>0
    AND INSTR('NU0NU1NU2NU3SC0',CITY_CODE) =0
    and ISS.item_type_id in ('SM17')
    group by ISS.item_type_id --
    I will re-write above query & i have been using queries like :-
    SELECT ISS.item_type_id,count(1) qty
    FROM ppbs_INV_SIM_SERIAL ISS
    WHERE INSTR('ROAAIT',STATUS)>0
    AND INSTR('NU0NU1NU2NU3SC0',CITY_CODE) =0
    and ISS.item_type_id in ('SM17') and item_type_id in
    (select item_type_id from ppbs_invoice_detail where
    trunc(created_date) between '01-jul-05' and '04-jul-05' and item_type_id=ISS.item_type_id)
    group by ISS.item_type_id
    my doubt here is that the sub-query in the first query is coming before i use the table 'ppbs_inv_sim_serial ISS' whereas in the second query, the table use 'ppbs_inv_sim_serial ISS' is coming before the sub-query use. I have been using queries where table name is defined before the sub-query.
    I hope, my question is clear. Please help in solving the doubt.
    Regards.

    I don't see a problem with the table aliasing that you seem to doubt, but your first query won't run. I boiled the thing down to basics: SQL>create table t1 (one number, val_1 number );
    Table created.
    SQL>create table t2 (one number, val_2 number );
    Table created.
    SQL>insert into t1 values (1,1);
    1 row created.
    SQL>insert into t2 values (1,2);
    1 row created.
    SQL>select a.one, count(1) + ( select sum(val_2) from t2 where t2.one = a.one) qty
      2  from  t1 a
      3  group by one;
    select a.one, count(1) + ( select sum(val_2) from t2 where t2.one = a.one) qty
    ERROR at line 1:
    ORA-00979: not a GROUP BY expression
    SQL>
    SQL>select a.one, count(1) qty
      2  from   t1 a
      3  where  a.one in ( select one from t2 where one = a.one)
      4  group by one;
           ONE        QTY
             1          1It's superfluous to "where a.one in ( select.. where = a.one) but that's your code basically. I would just do "="

  • Correlated sub-query/outer join problem

    Hi,
    I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
    The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
    The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
    select b.book_from,
         b.book_to,
         b.flat_rate,
         nvl(c.discount,0),
         p.hourly,
         p.half_day,
         p.daily,
         p.discountable,
         p.surcharge,
         l.evening_start,
         nvl(b.full_day,'N')
    from booking.bookings b,
    booking.customer c,
    booking.room_prices p,
    booking.rooms r,
    booking.location l
    where b.id = 9272
    and c.id = b.customer
    and b.room = p.room
    and b.room = r.id
    and r.loc = l.id
    and p.from_date =
    select max(p2.from_date)
    from booking.room_prices p2
    where p2.room = p.room
    and p2.from_date < b.book_from
    Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
    Thanks,
    Hazel

    Thanks for both of your responses.
    Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
    Here are some table creation scripts and test data to insert:
    CREATE TABLE BOOKINGS
    ID NUMBER NOT NULL,
    ROOM NUMBER NOT NULL,
    CUSTOMER NUMBER NOT NULL,
    BOOK_FROM DATE NOT NULL,
    BOOK_TO DATE NOT NULL,
    CONFIG VARCHAR2(24) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DELEGATES NUMBER,
    NARRATIVE VARCHAR2(256),
    CONTACT_DETAILS VARCHAR2(400),
    CONFIRMED VARCHAR2(1),
    CANC_REASON NUMBER,
    FULL_DAY VARCHAR2(1),
    FLAT_RATE NUMBER,
    STANDBY NUMBER,
    TOTAL_STANDBY_TIME DATE,
    PRE_STANDBY_TIME DATE,
    PRE_STANDBY NUMBER,
    GL_CODE VARCHAR2(20)
    CREATE TABLE CUSTOMER
    ID NUMBER NOT NULL,
    CUSTOMER VARCHAR2(160) NOT NULL,
    CONTACT_ADDRESS VARCHAR2(240),
    CONTACT_TELEPHONE VARCHAR2(20),
    CONTACT_EMAIL VARCHAR2(160),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DISCOUNT NUMBER(5,2),
    CUST_TYPE VARCHAR2(1),
    CONTACT_FAX VARCHAR2(20),
    DEBTOR_NO VARCHAR2(20),
    BC_CONTACT VARCHAR2(64)
    CREATE TABLE ROOMS
    ID NUMBER NOT NULL,
    LOC NUMBER NOT NULL,
    NAME VARCHAR2(160) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    ACTIVE VARCHAR2(1),
    ROOM_DESC VARCHAR2(2000)
    CREATE TABLE LOCATION
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240) NOT NULL,
    ADDRESS VARCHAR2(240),
    PCODE VARCHAR2(8),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    CONF_RDF VARCHAR2(10),
    CLOSING VARCHAR2(5),
    EVENING_START VARCHAR2(5)
    CREATE TABLE ROOM_PRICES
    ROOM NUMBER NOT NULL,
    FROM_DATE DATE NOT NULL,
    HOURLY NUMBER(6,2),
    HALF_DAY NUMBER(6,2),
    DAILY NUMBER(6,2),
    DISCOUNTABLE VARCHAR2(1),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    SURCHARGE NUMBER(6,2)
    Insert into bookings
    (ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
    Values
    (9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
    Insert into customer
    (ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
    Values
    (4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
    Insert into rooms
    (ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
    Values
    (7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
    Insert into location
    (ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
    Values
    (308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
    Thanks,
    Hazel

  • Filter query with sub query using Dropdown box

    Dear Community,
    I have 2 queries
    1. Main Query with 2 fields:  Project | Project value
    2. Sub Query with 2 fields:  Project group | Project
    Project group can be belonging to number of projects and project can be belong to number of project group (Many to Many).
    My customer wants the main query will open without any filtering.
    When I choose project group from WAD dropdown box, the main query will filtering all the projects that belong to the project group.
    I create WAD; define dropdown box as sub query, and Analysis as main query.
    In the dropdown box I choose "data binding" char and create command "set selection state by binding" (project to project) but it doesnu2019t work. 
    I also try to do this by Replacement Path in the main query, but the variable requires the attribute will be ready for input.
    Thanks a lot
    Yaniv

    I am not sure about your comments on replacement path variable. Without having tried it, here is what I would have attempted:
    The main query needs to use a replacement path variable for Project that is replaced by the results of the sub-query. Sub-query would have a regular input variable for project group. (as a quick test, if you had one analysis item for main query with variable input enabled, it should prompt you to enter Project group).
    Now the drop-down needs to be associated with a javascript function. The javascript function needs to implement command "Set variable state" for the main query data provider to selected value of the drop-down.
    The drop-down should be associated with the sub-query data provider, just used to populate the list of values in drop-down.

  • Scoping violation in sub-query

    I created a sql in Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 to query Oracle Purchasing tables. The user wants to know an estimate of the number of business days it takes to approve a release once it is created. I created a subquery as follows:
    Select Papf.Full_Name As Approver
    , Pah.Action_Date As Approved_Date
    , Por.Creation_Date
    , Trunc(Pah.Action_Date) - Trunc(Por.Creation_Date) As Days
    , (Select Count(*)
    From (Select Level, (Pah.Action_Date+1)-Level My_Date From Dual
    Connect By Level < Trunc(Pah.Action_Date+1) - Trunc(por.creation_Date)
    ) Where To_Char(My_Date, 'DY') In ('MON', 'TUE', 'WED', 'THU', 'FRI')) As Days2Approve
    FROM Apps.Po_Headers_All Poh
    , Apps.Po_Releases_All Por
    , Apps.Po_Lines_All Pol
    , Apps.Po_Action_History Pah
    …etc.
    When I run the query I get the following error message:
    ORA-00904: "POR"."CREATION_DATE": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Error at Line: 193 Column: 54
    I know the sub-query conceptually sound because if I run the sql below with dummy dates I get 17 which is correct.
    Select Count(*)
    From (SELECT level, (to_date('24-JAN-2013')+1)-level my_date From Dual
    Connect By Level < Trunc(To_Date('24-JAN-2013')+1) - Trunc(To_Date('01-JAN-2013'))
    ) Where To_Char(My_Date, 'DY') In ('MON', 'TUE', 'WED', 'THU', 'FRI')
    How do I pass Pah.Action_Date & por.creation_Date to the sub-query without getting what appears to be scoping violation?

    Hi,
    You can avoid the problem by not using a nested sub-query:
        SELECT  COUNT (*)
        FROM    dual
        CONNECT BY   LEVEL  < TRUNC (pah.action_date + 1)
                   - TRUNC (por.creation_date)
        WHERE   TO_CHAR ( pah.action_date + 1 - LEVEL
                          , 'DY'
                  ) NOT IN ('SAT', 'SUN')
    ) AS days2approve 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ {message:id=9360002}

  • Max (date) in sub-query

    I have an issue with a big view and several queries running on it where the max (date) is required in the sub-select (example below). When I run traces and explain, the perf problem is when the where cluase is evaluated, the view is pulled second time - so I basically use this view twice. The fact that the date in the underlined table is indexed did not help.
    I tried to use "ROW_NUMBER() OVER (ORDER BY date ASC) AS row_number, " rather to select the max(date) in teh sub query but I get only 1 records returned by the query instead the expected about 25,000.
    Need help on how to correct the max(date) to perform better and also to understand how to correct the ROW_NUMBER() not to limit me to 1 row.
    Thanks a lot for the help, Tom
    create view test_date as select * from user_objects;
    select * --(I have specific columns in the real query)
    from test_date t1
    where LAST_DDL_TIME in
    (select max(LAST_DDL_TIME)
    from test_date t2
    where t1.OBJECT_ID=t2.OBJECT_ID --(more clauses to limit the result but not reflecting the problem)
    and t1.OBJECT_NAME =t2.OBJECT_NAME
    and OBJECT_TYPE not in('TABLE')
    group by t2.OBJECT_ID , t2.OBJECT_NAME )

    I got the query to run - with dense ranck and row-Number I get the same results. My partition by cluse was wrong. But the perfromance is not much better.
    Any other idea on how to optimize a query that uses pattern like below and needs to return all rows from a table that have the max enter date.
    Thanks a lot, tom
    Example:
    col1 col2 col3
    1 sysdate 'I need this record'
    2 sysdate 'I need this record'
    3 sysdate 'I need this record'
    4 sysdate 'I do NOT need this record'
    5 sysdate 'I do NOT need this record'
    5 sysdate+3 'I need this record'
    5 sysdate+2 'I do NOT need this record'
    4 sysdate+3 'I need this record'
    4 sysdate+2 'I do NOT need this record'
    4 sysdate+1 'I do NOT need this record'
    My query corrently is using the following construcion:
    select col1, col2 , col3
    from test_table t
    where 1,2,3
    and col3 = (select max(col3) from test_table t2 where t2.col1 = t.col1) group by t2.col1

  • Can i use Sub Query Factoring Here ?

    Hi;
    SQL>SELECT * FROM V$VERSION;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionSQL
    select /*+ PARALLEL(det, 4) */ '12062' snapshot_id,det.journal_entry_line_id, det.accounting_date,det.company_code,det.account_number,
    det.transaction_id, det.transaction_id_type, det.amount,det.currency_code,det.debit_or_credit,det.category,det.subcategory,det.reference1,det.reference1_type,
    det.reference2,det.reference2_type,det.gl_batch_id,det.marketplace_id,det.cost_center,det.gl_product_line,det.location,det.project,det.sales_channel,
    det.created_by,det.creation_date,det.last_updated_by,det.last_updated_date,agg.age,last_day(to_date('04/21/2010','MM/DD/YYYY')) snapshot_day
    from
    select company_code, account_number, transaction_id,
    decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,
    (last_day(to_date('04/21/2010','MM/DD/YYYY')) - min(z.accounting_date) ) age,sum(z.amount)
    from
         select /*+ PARALLEL(use, 2) */    company_code,substr(account_number, 1, 5) account_number,transaction_id,
         decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,use.amount,use.accounting_date
         from financials.unbalanced_subledger_entries use
         where use.accounting_date >= to_date('04/21/2010','MM/DD/YYYY')
         and use.accounting_date < to_date('04/21/2010','MM/DD/YYYY') + 1
    UNION ALL
         select /*+ PARALLEL(se, 2) */  company_code, substr(se.account_number, 1, 5) account_number,transaction_id,
         decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,se.amount,se.accounting_date
         from financials.temp2_sl_snapshot_entries se,financials.account_numbers an
         where se.account_number = an.account_number
         and an.subledger_type in ('C', 'AC')
    ) z
    group by company_code,account_number,transaction_id,decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type)
    having abs(sum(z.amount)) >= 0.01
    ) agg,
         select /*+ PARALLEL(det, 2) */ det.journal_entry_line_id,  det.accounting_date, det.company_code, det.account_number, det.transaction_id,  decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,
         det.amount, det.currency_code, det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type,
         det.gl_batch_id, det.marketplace_id, det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date,
         det.last_updated_by, det.last_updated_date
         from financials.unbalanced_subledger_entries det
         where accounting_date >= to_date('04/21/2010','MM/DD/YYYY')
         and accounting_date < to_date('04/21/2010','MM/DD/YYYY') + 1
    UNION ALL
    select /*+ PARALLEL(det, 2) */  det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id,
    decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,  det.amount, det.currency_code,
    det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type, det.gl_batch_id, det.marketplace_id,
    det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date, det.last_updated_by, det.last_updated_date
    from financials.temp2_sl_snapshot_entries det,financials.account_numbers an
    where det.account_number = an.account_number
    and an.subledger_type in ('C', 'AC')
    ) det
                       where agg.company_code = det.company_code
                       and agg.account_number = substr(det.account_number, 1, 5)
                       and agg.transaction_id = det.transaction_id
                       and agg.transaction_id_type = det.transaction_id_type
    /Execution Plan
    | Id  | Operation                          | Name                         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT                   |                              |    12M|  8012M|       |   541K  (1)| 01:48:21 |        |      |            |
    |   1 |  PX COORDINATOR                    |                              |       |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)              | :TQ10005                     |    12M|  8012M|       |   541K  (1)| 01:48:21 |  Q1,05 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN BUFFERED              |                              |    12M|  8012M|  1098M|   541K  (1)| 01:48:21 |  Q1,05 | PCWP |            |
    |   4 |     PX RECEIVE                     |                              |    35M|  3992M|       |   166K  (2)| 00:33:16 |  Q1,05 | PCWP |            |
    |   5 |      PX SEND HASH                  | :TQ10003                     |    35M|  3992M|       |   166K  (2)| 00:33:16 |  Q1,03 | P->P | HASH       |
    |   6 |       VIEW                         |                              |    35M|  3992M|       |   166K  (2)| 00:33:16 |  Q1,03 | PCWP |            |
    |*  7 |        FILTER                      |                              |       |       |       |            |          |  Q1,03 | PCWC |            |
    |   8 |         HASH GROUP BY              |                              |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,03 | PCWP |            |
    |   9 |          PX RECEIVE                |                              |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,03 | PCWP |            |
    |  10 |           PX SEND HASH             | :TQ10001                     |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,01 | P->P | HASH       |
    |  11 |            HASH GROUP BY           |                              |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,01 | PCWP |            |
    |  12 |             VIEW                   |                              |    35M|  4528M|       |   164K  (1)| 00:33:00 |  Q1,01 | PCWP |            |
    |  13 |              UNION-ALL             |                              |       |       |       |            |          |  Q1,01 | PCWP |            |
    |  14 |               PX BLOCK ITERATOR    |                              |    11 |   539 |       |  1845   (1)| 00:00:23 |  Q1,01 | PCWC |            |
    |* 15 |                TABLE ACCESS FULL   | UNBALANCED_SUBLEDGER_ENTRIES |    11 |   539 |       |  1845   (1)| 00:00:23 |  Q1,01 | PCWP |            |
    |* 16 |               HASH JOIN            |                              |    35M|  2012M|       |   163K  (1)| 00:32:37 |  Q1,01 | PCWP |            |
    |  17 |                BUFFER SORT         |                              |       |       |       |            |          |  Q1,01 | PCWC |            |
    |  18 |                 PX RECEIVE         |                              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
    |  19 |                  PX SEND BROADCAST | :TQ10000                     |    21 |   210 |       |     2   (0)| 00:00:01 |        | S->P | BROADCAST  |
    |* 20 |                   TABLE ACCESS FULL| ACCOUNT_NUMBERS              |    21 |   210 |       |     2   (0)| 00:00:01 |        |      |            |
    |  21 |                PX BLOCK ITERATOR   |                              |    56M|  2701M|       |   162K  (1)| 00:32:35 |  Q1,01 | PCWC |            |
    |  22 |                 TABLE ACCESS FULL  | TEMP2_SL_SNAPSHOT_ENTRIES    |    56M|  2701M|       |   162K  (1)| 00:32:35 |  Q1,01 | PCWP |            |
    |  23 |     PX RECEIVE                     |                              |    35M|    18G|       | 82859   (1)| 00:16:35 |  Q1,05 | PCWP |            |
    |  24 |      PX SEND HASH                  | :TQ10004                     |    35M|    18G|       | 82859   (1)| 00:16:35 |  Q1,04 | P->P | HASH       |
    |  25 |       BUFFER SORT                  |                              |    12M|  8012M|       |            |          |  Q1,04 | PCWP |            |
    |  26 |        VIEW                        |                              |    35M|    18G|       | 82859   (1)| 00:16:35 |  Q1,04 | PCWP |            |
    |  27 |         UNION-ALL                  |                              |       |       |       |            |          |  Q1,04 | PCWP |            |
    |  28 |          PX BLOCK ITERATOR         |                              |    11 |  2255 |       |   923   (1)| 00:00:12 |  Q1,04 | PCWC |            |
    |* 29 |           TABLE ACCESS FULL        | UNBALANCED_SUBLEDGER_ENTRIES |    11 |  2255 |       |   923   (1)| 00:00:12 |  Q1,04 | PCWP |            |
    |* 30 |          HASH JOIN                 |                              |    35M|  7514M|       | 81936   (1)| 00:16:24 |  Q1,04 | PCWP |            |
    |  31 |           PX RECEIVE               |                              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,04 | PCWP |            |
    |  32 |            PX SEND BROADCAST       | :TQ10002                     |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,02 | P->P | BROADCAST  |
    |  33 |             PX BLOCK ITERATOR      |                              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,02 | PCWC |            |
    |* 34 |              TABLE ACCESS FULL     | ACCOUNT_NUMBERS              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,02 | PCWP |            |
    |  35 |           PX BLOCK ITERATOR        |                              |    56M|    11G|       | 81840   (1)| 00:16:23 |  Q1,04 | PCWC |            |
    |  36 |            TABLE ACCESS FULL       | TEMP2_SL_SNAPSHOT_ENTRIES    |    56M|    11G|       | 81840   (1)| 00:16:23 |  Q1,04 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - access("AGG"."COMPANY_CODE"="DET"."COMPANY_CODE" AND "AGG"."ACCOUNT_NUMBER"=SUBSTR("DET"."ACCOUNT_NUMBER",1,5) AND
                  "AGG"."TRANSACTION_ID"="DET"."TRANSACTION_ID" AND "AGG"."TRANSACTION_ID_TYPE"="DET"."TRANSACTION_ID_TYPE")
       7 - filter(ABS(SUM(SYS_OP_CSR(SYS_OP_MSR(SUM("Z"."AMOUNT"),MIN("Z"."ACCOUNTING_DATE")),0)))>=0.01)
      15 - filter("USE"."ACCOUNTING_DATE"<TO_DATE(' 2010-04-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "USE"."ACCOUNTING_DATE">=TO_DATE('
                  2010-04-21 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      16 - access("SE"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
      20 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
      29 - filter("ACCOUNTING_DATE"<TO_DATE(' 2010-04-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ACCOUNTING_DATE">=TO_DATE(' 2010-04-21
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      30 - access("DET"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
      34 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
                    This query is failing due to TEMP issue (TEMP SPACE out of space)
    My TEMP tablespace is 70GB and no one is using TEMP space while this query is in execution.
    PGA=16 GB.
    What i can see from execution plan is : Two large resultsets AGG (13Million) and DET (135 Million) is being joined HASH JOIN BUFFERED. Which is getting spilled to TEMP space causing TEMP outage.
    Is there any way, i can re-write this query (probably using SUB QUERY FACTORING...WITH CLAUSE) so that reduce two times access to TEMP2_SL_SNAPSHOT_ENTRIES table. TEMP2_SL_SNAPSHOT_ENTRIES is 12 GB non partition table and i cannot use any other filter to restrict rows from this table.

    Adding more information here :
    Inner sub query (Which forms DET-bottom)
    select /*+ PARALLEL(det, 2) */  det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id,
    decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,  det.amount, det.currency_code,
    det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type, det.gl_batch_id, det.marketplace_id,
    det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date, det.last_updated_by, det.last_updated_date
    from financials.temp2_sl_snapshot_entries det,financials.account_numbers an
    where det.account_number = an.account_number
    and an.subledger_type in ('C', 'AC');
    Plan hash value: 976020246
    | Id  | Operation               | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT        |                           |    35M|  7514M|   163K  (1)| 00:32:47 |        |      |            |
    |   1 |  PX COORDINATOR         |                           |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)   | :TQ10001                  |    35M|  7514M|   163K  (1)| 00:32:47 |  Q1,01 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN            |                           |    35M|  7514M|   163K  (1)| 00:32:47 |  Q1,01 | PCWP |            |
    |   4 |     BUFFER SORT         |                           |       |       |            |          |  Q1,01 | PCWC |            |
    |   5 |      PX RECEIVE         |                           |    21 |   210 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
    |   6 |       PX SEND BROADCAST | :TQ10000                  |    21 |   210 |     2   (0)| 00:00:01 |        | S->P | BROADCAST  |
    |*  7 |        TABLE ACCESS FULL| ACCOUNT_NUMBERS           |    21 |   210 |     2   (0)| 00:00:01 |        |      |            |
    |   8 |     PX BLOCK ITERATOR   |                           |    56M|    11G|   163K  (1)| 00:32:45 |  Q1,01 | PCWC |            |
    |   9 |      TABLE ACCESS FULL  | TEMP2_SL_SNAPSHOT_ENTRIES |    56M|    11G|   163K  (1)| 00:32:45 |  Q1,01 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - access("DET"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
       7 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
    Statistics
             31  recursive calls
              3  db block gets
        1634444  consistent gets
        1625596  physical reads
            636  redo size
    1803659818  bytes sent via SQL*Net to client
         125054  bytes received via SQL*Net from client
          11331  SQL*Net roundtrips to/from client
              3  sorts (memory)
              0  sorts (disk)
       56645822  rows processedOther sub query (that forms AGG)
         select /*+ PARALLEL(se, 2) */  company_code, substr(se.account_number, 1, 5) account_number,transaction_id,
         decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,se.amount,se.accounting_date
         from financials.temp2_sl_snapshot_entries se,financials.account_numbers an
         where se.account_number = an.account_number
         and an.subledger_type in ('C', 'AC');
    Plan hash value: 976020246
    | Id  | Operation               | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT        |                           |    35M|  2012M|   163K  (1)| 00:32:37 |        |      |            |
    |   1 |  PX COORDINATOR         |                           |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)   | :TQ10001                  |    35M|  2012M|   163K  (1)| 00:32:37 |  Q1,01 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN            |                           |    35M|  2012M|   163K  (1)| 00:32:37 |  Q1,01 | PCWP |            |
    |   4 |     BUFFER SORT         |                           |       |       |            |          |  Q1,01 | PCWC |            |
    |   5 |      PX RECEIVE         |                           |    21 |   210 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
    |   6 |       PX SEND BROADCAST | :TQ10000                  |    21 |   210 |     2   (0)| 00:00:01 |        | S->P | BROADCAST  |
    |*  7 |        TABLE ACCESS FULL| ACCOUNT_NUMBERS           |    21 |   210 |     2   (0)| 00:00:01 |        |      |            |
    |   8 |     PX BLOCK ITERATOR   |                           |    56M|  2701M|   162K  (1)| 00:32:35 |  Q1,01 | PCWC |            |
    |   9 |      TABLE ACCESS FULL  | TEMP2_SL_SNAPSHOT_ENTRIES |    56M|  2701M|   162K  (1)| 00:32:35 |  Q1,01 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - access("SE"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
       7 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
    Statistics
             31  recursive calls
              3  db block gets
        1634444  consistent gets
        1625596  physical reads
            592  redo size
    1803659818  bytes sent via SQL*Net to client
         125054  bytes received via SQL*Net from client
          11331  SQL*Net roundtrips to/from client
              3  sorts (memory)
              0  sorts (disk)
       56645822  rows processed

  • Correlated Sub Query

    Deal All,
    Please help me to know list of Drawback/Limitation of Corellated Subquery.
    i want to Optimize the correlated sub Query.
    Thanks,
    Dinesh Babu
    9818783322

    See:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3167884300346662300
    It would be nice to know your database version.
    It would be nice to know what query you're executing
    It would be nice to see an execution plan
    It would be nice if you'd first read the SQL and PL/SQL FAQ, especially:
    SQL and PL/SQL FAQ
    and
    *3. How to improve the performance of my query? / My query is running slow*.
    When your query takes too long...
    How to post a SQL statement tuning request
    SQL and PL/SQL FAQ

  • Nested sub query

    HI,
    how ro write nested multiple row ( row should consist range of values )sub query between tables if they dont have any common column.
    Based on this weight range I have to group the other columns.
    For eg:
    My table should contain
    weight-range:
    1-> 2
    2->3
    3->4
    etc

    Please repost your question adding clarity and an example so we can understand what you are asking. Also include your full version number.
    SELECT * FROM v$version;

  • Hi! Everyone, I have some problems with JOIN and Sub-query; Could you help me, Please?

    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!

    Hi,
    fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!
    As the others have said, the execution plan will give you a better idea about which is faster.
    If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible.  For example, include field3 in both queries, or ignore field3 in both queries.
    In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess.  I can't see your execution plans.
    In general, simpler code is faster, and better in other ways, too.  In this case
    tableB
    is simpler than
    (SELECT field1, field2  FROM tableB)
    Why do you want a sub-query in this example?

Maybe you are looking for

  • Playing video AND audio through TV speakers using Mini Display to HDMI adapter

    I have a late 2011 MBP and want to hear the sound of the videos I'm running on my MBP through the speakers of my LG HDTV.  I have used a Belkin Mini DisplayPort to HDMI adapter (model f2cd021eb) plugged in to my MBP with an HDMI cable running from it

  • Capture generated html output from jsf page in bean

    Hi Member, I have need to capture the html output coming form jsf page. means aftr rendering what html is displayed before user, we have need to get it in programm. like if we use: <h:dataTable......> <h:colum>heloo</h:column> </h:dataTable> then the

  • OC4J 10.1.2 - No XPathFactory implementation found for the object model

    Hello, We are doing some maintenance on an old 10.1.2.3.0 container. The project has to be extended with a library built with xml-apis-1.3.03.jar. I know you will suggest a upgrade, but that is a no-go - sorry, since other projects also are running o

  • Round and round with authorizing

    Trying to update my iPod, I get the msg that I need to authorize my computer to play 144 bought songs or they will be deleted from my iPod. When I authorize it I get a msg saying the computer is already authorized--which I knew. However, when I close

  • Can't access content library in iMovie 10.0.6

    I have updated to OS X Yosemite and I am using iMovie 10.0.6 but there is no content library in the side bar and if I try to access it through the window button and then go to content library they are faded and I am unable to click them. Is there any