Please help in query performance

select bg.billing_group_id,r.rating_result, count(*),rc.source,rc.description
from rejected_record r,
result_code@RD rc,
terminal_device@cust td,
personal_account_td@cust patd,
personal_account@cust pa,
billing_group@cust bg,
-- tariff_plan@rd tp,
(select pcs.primary_session_id, pcs.charging_date
from pcs@umr_interface
where pcs.range_cdr_file_source not like 'HOT%'
--and lower(pcs.RANGE_CDR_FILE_SOURCE) not like 'rec%'
-- and lower(pcs.RANGE_CDR_FILE_SOURCE) not like 'sms%'
-- and lower(pcs.RANGE_CDR_FILE_SOURCE) not like 'data%'
-- and pcs.CHARGING_TYPE_ID = 1
and pcs.charging_date between '20/Aug/2010' and '21/Sep/2010') t
where r.primary_session_id = t.primary_session_id
and rc.code (+)= r.rating_result
and td.terminal_device_id = patd.terminal_device_id
and patd.personal_account_id = pa.personal_account_id
and r.calling_party_number_rid = td.msisdn
and pa.billing_group_id = bg.billing_group_id
and r.is_precharged=0
--and td.tariff_plan_id=tp.tariff_plan_id
and (nvl(td.date_to,'01.01.2000')='01.01.2000')
and (nvl(pa.date_to,'01.01.2000')='01.01.2000')
and (nvl(patd.date_to,'01.01.2000')='01.01.2000')
group by r.rating_result, rc.source, rc.description,bg.billing_group_id
order by r.rating_result
SQL> select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE     9.2.0.8.0     Production
TNS for Solaris: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
SQL>
Above select query took only 10 mins when those nvl functions where not there..
but when these nvl fuctions are added this takes lot of time....
please help to optimce it..
first i tried with is null.. it took lot of time.. ten i replaced it with nvl function...
please somebody help to optimize this query

Check out these links:
{message:id=1812597}
{thread:id=863295}

Similar Messages

  • Please help for using perform in SAP script

    As subject.
    My sap script code as below:
    /: PERFORM GET_CHAMT_DATE IN PROGRAM ZRAP004
    /:USING    &SPELL-WORD&
    /:CHANGING &SPELL-WORD&
    /:ENDPERFORM
    My program ZRAP004 code as below:
    FORM get_chamt_date USING u_iword TYPE spell-word
                       CHANGING u_oword TYPE spell-word.
    CONCATENATE u_iword '元整'(t01) INTO u_oword.
    endform.
    This form is for check printing.
    It's by standard function 'F110' to excute check printing.
    But when i finished this transaction. System return error message as below:
    <b>This routine contains 2 formal parameters, but the current call
    contains 4 actual parameters.</b>
    Please help. Thanks a lot!!

    Hiii
    PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK
    /:USING &EKKO-EBELN&
    /:CHANGING &CDECENT&
    /:ENDPERFORM
    The report :
    REPORT zkrpmm_perform_z1medruck .
    DATA : BEGIN OF it_input_table OCCURS 10.
           INCLUDE STRUCTURE itcsy.
    DATA : END OF it_input_table.
    déclaration de la table output_table contenant les
    variables exportées
    DATA : BEGIN OF it_output_table OCCURS 0.
           INCLUDE STRUCTURE itcsy.
    DATA : END OF it_output_table.
    DATA : w_ebeln LIKE ekko-ebeln,
          w_vbeln LIKE vbak-vbeln,
          w_zcdffa LIKE vbak-zcdffa.
    FORM CDE_CENT
    FORM cde_cent TABLES input output.
    it_input_table[] = input[].
    it_output_table[] = output[].
    READ TABLE it_input_table INDEX 1.
    MOVE it_input_table-value TO w_ebeln.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
               input  = w_ebeln
          IMPORTING
               output = w_ebeln.
    SELECT SINGLE zcdffa FROM ekko
    INTO w_zcdffa
    WHERE ebeln = w_ebeln.
    it_output_table-name = 'CDECENT'.
    MOVE w_zcdffa TO it_output_table-value.
    MODIFY it_output_table INDEX 1.
    output[] = it_output_table[].
    ENDFORM.

  • This query is running slw...please help to improve performance

    SELECT Listnontranstextid,
           Listnontransshort,
           Listnontransmedium,
           Listnontransextended
      FROM (WITH TEXT_T
                    AS (SELECT /*+ index(TT pk_text_translation) */TT.TEXTID,
                               TT.short,
                               TT.medium,
                               TT.extended
                          FROM TEXT_TRANSLATION TT
                         WHERE TT.Active = 1
                               AND (   TT.Short <> 'Null'
                                    OR TT.Medium <> 'Null'
                                    OR TT.Extended <> 'Null')
                               AND TT.Languageid = @Langid
                 FUNC AS (SELECT FN.ID
                            FROM Function_ Fn
                                 INNER JOIN Function_Type Fnty
                                    ON Fn.Functiontype = Fnty.Functiontype
                                       AND Fnty.Active = 1
                                 INNER JOIN Operation_Step_Function Osf
                                    ON (Osf.Functionid = Fn.Id)
                                       AND Osf.Active = 1
                                 INNER JOIN Operation_Step Os
                                    ON Os.Id = Osf.Operationstepid
                                       AND Os.Active = 1
                                 INNER JOIN Operation Op
                                    ON     Op.Id = Os.Operationid
                                       AND op.defaultoperationrevision = 1
                                       AND Op.Active = 1
                                       AND Op.Revisionstatusid NOT IN (2)
                           -- 2 means Operation Staus =Cancelled
                           WHERE FN.ACTIVE = 1
            SELECT TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM function_translation ft
                   INNER JOIN TEXT_T TT
                      ON (TT.Textid = Ft.Textid)
                   INNER JOIN FUNC F
                      ON (F.ID = Ft.Functionid)
             WHERE Ft.ACTIVE = 1
            UNION
            SELECT /*+ index(Forout IF_FUNCTION_OUTPUT_ROUTING_02) */ TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM Function_Output Fo
                   INNER JOIN Function_Output_Routing Forout
                      ON Forout.Functionoutputid = Fo.Id
                   INNER JOIN TEXT_T TT
                      ON TT.Textid = Forout.PromptTextid
                   INNER JOIN Function_Output_Routing_Type Fort
                      ON Fort.Id = Forout.Outputroutingtypeid
                   INNER JOIN Text_Translation Ttdt
                      ON     Ttdt.Textid = Fort.Textid
                         AND Ttdt.Languageid = @Langid
                         AND UPPER (Ttdt.Extended) = ('USER')
                   INNER JOIN FUNC F
                      ON F.ID = FO.Functionid
            UNION
            SELECT TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM Function_Input Fi
                   INNER JOIN TEXT_T TT
                      ON (TT.Textid = Fi.Prompttextid)
                   INNER JOIN Function_Input_Source_Type Fist
                      ON Fist.Id = Fi.Inputsourcetypeid AND Fist.Active = 1
                   INNER JOIN Text_Translation Ttdt
                      ON     Ttdt.Textid = Fist.Textid
                         AND Ttdt.Active = 1
                         AND Ttdt.Languageid = @Langid
                         AND UPPER (Ttdt.Extended) = ('USER')
                   INNER JOIN FUNC F
                      ON F.ID = FI.Functionid
            UNION
            SELECT TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM Function_Input_value Fiv
                   INNER JOIN function_input fi
                      ON fi.id = fiv.functioninputid
                   INNER JOIN TEXT_T TT
                      ON (TT.Textid = Fiv.textid)
                   INNER JOIN Function_Input_Source_Type Fist
                      ON Fist.Id = Fi.Inputsourcetypeid AND Fist.Active = 1
                   INNER JOIN Text_Translation Ttdt
                      ON     Ttdt.Textid = Fist.Textid
                         AND Ttdt.Active = 1
                         AND Ttdt.Languageid = @Langid
                         AND UPPER (Ttdt.Extended) = ('USER')
                   INNER JOIN FUNC F
                      ON F.ID = FI.Functionid
            UNION
            SELECT TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM    cob_t_ngmes_master_data ctnmt
                   INNER JOIN
                      text_translation tt
                   ON tt.textid = ctnmt.textid
             WHERE tt.languageid = @Langid 
            UNION  -- Swanand, PR 190540, Added this clause to get the reasoncodes
            SELECT TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM Reason_Code RC
                   INNER JOIN Reason_Type RT
                      ON RT.ReasonType = RC.ReasonType
                   INNER JOIN TEXT_TRANSLATION TT1
                      ON     TT1.textid = RT.textid
                         AND RT.ACTIVE = 1
                         AND TT1.ACTIVE = 1
                         AND (   TT1.Short <> 'Null'
                              OR TT1.Medium <> 'Null'
                              OR TT1.Extended <> 'Null')
                   INNER JOIN TEXT_T TT
                      ON TT.textid = RC.textid AND RC.ACTIVE = 1
             WHERE TT1.Languageid = @Langid 
            UNION
            SELECT TT.Textid AS Listnontranstextid,
                   TT.Short AS Listnontransshort,
                   TT.Medium AS Listnontransmedium,
                   TT.Extended AS Listnontransextended
              FROM NSPT_T_Event_Type ET
                   INNER JOIN TEXT_TRANSLATION TT1 ON TT1.TextID =
         ET.TextID AND TT1.ACTIVE = 1
                   INNER JOIN TEXT_T TT
                      ON TT.TextID = TT1.TextID
             WHERE  TT1.Languageid = @Langid  
                       ORDER BY Listnontranstextid ASC) WHERE Listnontranstextid > @I_TextIDEdited by: 964145 on Oct 26, 2012 4:53 PM

    Duplicate post ? Query running slow....need performance tuning

  • [Oracle 8i] Help with query performance

    The following query is running VERY slowly for me:
    SELECT     oord.part_nbr
    ,     sopn.ord_nbr
    ,     sopn.sub_ord_nbr
    ,     sopn.major_seq_nbr
    ,     sopn.wctr_id
    ,     sopn.oper_desc
    ,     SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
    ,     pact.activity_date
    FROM     PACT pact
    ,     SOPN sopn
    ,     OORD oord
    WHERE     pact.order_nbr          = sopn.ord_nbr          AND
         pact.maj_seq_nbr     = sopn.major_seq_nbr     AND
         sopn.sub_ord_nbr     = pact.sub_order_nbr     AND
         sopn.ord_nbr          = oord.ord_nbr          AND
         sopn.sub_ord_nbr     = oord.sub_ord_nbr     AND
              pact.activity_date     >= ?          AND
              sopn.rework_ind          = 'N'          AND
              (oord.part_nbr, sopn.major_seq_nbr, sopn.wctr_id)
              NOT IN     (
                        SELECT     rout.doc_nbr
                        ,     rout.major_seq_nbr
                        ,     rout.wctr_id
                        FROM ROUT rout
                        WHERE     (rout.begn_eff_dt    <=SYSDATE)     AND
                             (rout.end_eff_dt    >SYSDATE)     AND
                             (rout.po_rework_ind    ='N')       
    GROUP BY     oord.part_nbr
    ,          sopn.ord_nbr
    ,          sopn.sub_ord_nbr
    ,          sopn.major_seq_nbr
    ,          sopn.wctr_id
    ,          sopn.oper_desc
    ,          pact.activity_dateI sent a request off to my IT department (specifically asking for the explain plan and tkprof, as described in the [main post on this topic|http://forums.oracle.com/forums/thread.jspa?threadID=501834] ), and they replied with a screen shot of the 'explain plan' the tool they use (Toad) provides.
    !http://temp-sample.webs.com/explain_plan.jpg!
    I don't know if anyone can help me based off this, since I know it's not really what the main post says to provide, but it's all I was given.
    My IT department also made a few changes to my original query (see below) and told me it got rid of one of the full scans of the PACT table, but they aren't sure why it helped, and I have to say I'm suspect of any fixes where it's not understood why it helped.
    SELECT     oord.part_nbr
    ,     sopn.ord_nbr
    ,     sopn.sub_ord_nbr
    ,     sopn.major_seq_nbr
    ,     sopn.wctr_id
    ,     sopn.oper_desc
    ,     SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
    ,     pact.activity_date
    FROM     PACT pact
    ,     SOPN sopn
    ,     OORD oord
    WHERE     sopn.ord_nbr          = pact.order_nbr     AND
         sopn.major_seq_nbr     = pact.maj_seq_nbr     AND
         pact.sub_order_nbr     = sopn.sub_ord_nbr     AND
         oord.ord_nbr           = sopn.ord_nbr          AND
         oord.sub_ord_nbr     = sopn.sub_ord_nbr     AND
         (pact.activity_date >= ?)               AND
         'N'               = sopn.rework_ind     AND
         pact.order_nbr          = oord.ord_nbr          AND
         oord.sub_ord_nbr = pact.sub_order_nbr          AND
         (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) NOT IN
              SELECT /*+ INDEX_JOIN(ROUT) */     rout.doc_nbr
              ,                    rout.major_seq_nbr
              ,                    rout.wctr_id
              FROM     ROUT rout
              WHERE     rout.begn_eff_dt     <= SYSDATE     AND
                   rout.end_eff_dt      > SYSDATE     AND
                   'N' = rout.po_rework_ind
    GROUP BY     oord.part_nbr
    ,          sopn.ord_nbr
    ,          sopn.sub_ord_nbr
    ,          sopn.major_seq_nbr
    ,          sopn.wctr_id
    ,          sopn.oper_desc
    ,          pact.activity_dateAny help on this would be appreciated... when I run this (right now) for 2-3 months of data, it takes a minimum of 3 hours to complete, and I'll eventually need to run this for up to a year's worth of data.

    Hi,
    Well, let's see.
    You get 156 rows returned using IN and 121 rows using exists.
    You need identify the 'missing records' and conclude if that's correct or not, I'm not able to do that from remote, without knowing your data or system.
    It would be helpful if we could see cost and cardinalities, you (or your IT dept.) can get them easily be running the queries from your SQL*Plus prompt.
    Type
    SET AUTOTRACE TRACEONLYbefore running the queries.
    That gives you the explain plan and additional statistics (sorts in memory and sorts to disk).
    Since you use a group by, and you're on 8i can you also post results of these queries:
    select banner from v$version;
    select name, value, isdefault from v$parameter where name like '%area%';Finally, does below query give you a different plan?
    select oord.part_nbr
    ,      oord.ord_nbr
    ,      oord.sub_ord_nbr
    ,      pact.major_seq_nbr
    ,      sopn.wctr_id
    ,      sopn.oper_desc
    ,      sum(pact.act_dlrs_earned + pact.act_brdn_dls_earned + pact.tool_dlrs_earned + pact.act_fix_brdn_dls_ea)
    ,      pact.activity_date
    from   oord oord 
    ,      pact pact
    ,      sopn sopn
    where  oord.ord_nbr       = pact.order_nbr
    and    oord.sub_ord_nbr   = pact.sub_order_nbr
    and    oord.ord_nbr       = sopn.ord_nbr
    and    oord.sub_ord_nbr   = sopn.sub_ord_nbr
    and    sopn.major_seq_nbr = pact.maj_seq_nbr
    and    (pact.activity_date >= ?)
    and    'N' = sopn.rework_ind
    and    (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) not in ( select rout.doc_nbr
                                                                    ,      rout.major_seq_nbr
                                                                    ,      rout.wctr_id
                                                                    from   rout rout
                                                                    where  rout.begn_eff_dt <= sysdate
                                                                    and    rout.end_eff_dt > sysdate
                                                                    and    'N' = rout.po_rework_ind)
    group  by oord.part_nbr
    ,         oord.ord_nbr
    ,         oord.sub_ord_nbr
    ,         pact.major_seq_nbr
    ,         sopn.wctr_id
    ,         sopn.oper_desc
    ,         pact.activity_date

  • Please help with query for 5 lastest opening balance  !!!!!!!!!!!

    Can anyone plese tell me or guide me how to write the query to show the 5 lastest opening balance from the A/R invoice on the specific BP partner?
    Example
    The box to input "BP partner"
    and then show,
    Lastest transaction | Ship date | Invoice number | Balance Amount | Culmulative
    1    
    2
    3
    4
    5
    Your help will be very very appreciated.

    This is very good but I would like to show only the top 5 remaining invoice. I think that I have to combine it with JDT1. I have seen one query that may be able to apply on my case.
    SELECT
    T1.CardCode + '' AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    T0.RefDate,
    CASE
         WHEN T0.TransType = 13 THEN 'IN'
         WHEN T0.TransType = 14 THEN 'CN'
         WHEN T0.TransType = 30 THEN 'JE'
         WHEN T0.TransType = 24 THEN 'RC'
         WHEN T0.TransType = 46 THEN 'PS'
         ELSE 'Error ! ! !'
    END AS 'Doc Type',
    T0.Ref1 'Doc. Number',
    ISNULL(T0.FCCurrency, ' - ') AS 'Ccy',
    (T0.BalFcDeb - T0.BalFcCred) AS 'Bal. F. Ccy',
    (T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate, '[%1]') <= -1)                     ,0) AS 'Future',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate, '[%1]') = 0)                         ,0) AS 'Current Mth',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate, '[%1]') = 1)                         ,0) AS '1 Mth Ago',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate, '[%1]') = 2)                         ,0) AS '2 Mth Ago',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate ,'[%1]') = 3)                         ,0) AS '3 Mth Ago',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate, '[%1]') between 4 and 6)    ,0) AS '4 - 6 Mth Ago',
    ISNULL((SELECT T0.BalDueDeb -T0.BalDueCred WHERE DateDiff(mm, T0.RefDate, '[%1]') >= 7)                       ,0) AS '>7 Mth Ago'
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C' and Balance != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    but still try to figure it out....

  • Help about query performance -Thanks

    Hi
    I have a j2ee web application with oracle database.
    I finish the function implementation by put all caculaton inside oracle query ( funciton (todayData - avg(historical data )) / std(historical data) and using group by and sub query .but performance is very slow about 3 minute whick is far from client's 10 second requirement.
    My question is if I take raw data from database and do the caculation part in Java will it be faster. Is there some other way to speed up the process?(historical data is big)
    Thanks for your time and help

    create a function index. after creation, see your sql using the function index
    this will be faster
    regards

  • Please Help this query should be simple :)

    Here is what I have written so far: Basically I want it to return all the locations like I have specified that do not have DA-REPL in the area_code table but it is just returning everything it seems.
    select l.location_no, l.zone_code, la.area_code
    from move.location l, move.location_area la
    where la.location_no = l.location_no
    and l.zone_code = 'Z-BIN'
    and (l.location_no like '%%-%%-2%%' or l.location_no like '%%-%%-1%%')
    and la.area_code != 'DA-REPL'
    order by 1
    Here is what my results look like:
    60-02-101     Z-BIN     WA-60
    60-02-101     Z-BIN     WA-BIN
    60-02-101     Z-BIN     WA-BINRESV
    60-02-101     Z-BIN     WA-PALLET
    60-02-102     Z-BIN     WA-60
    60-02-102     Z-BIN     WA-BIN
    60-02-102     Z-BIN     WA-BINRESV
    60-02-102     Z-BIN     WA-PALLET
    60-02-201     Z-BIN     WA-60
    60-02-201     Z-BIN     WA-BIN
    60-02-201     Z-BIN     WA-BINRESV
    60-02-201     Z-BIN     WA-PALLET
    Edited by: 906043 on Feb 20, 2012 2:23 PM

    906043 wrote:
    At it's most basic the query would look like this but this gives me 67,834 results I am dealing with a pretty big warehouse with many "la.area_code" entries I am only trying to get the locations in a specific zone('Z-BIN') that do not have 'DA-REPL' as an la.area_code as this would cause that location never to get replenishments when it becomes empty.
    select l.location_no, l.zone_code, la.area_code
    from move.location l, move.location_area la
    where la.location_no = l.location_no
    l.zone_code = 'Z=BIN'
    and la.area_code != 'DA-REPL'
    order by 1
    Not sure if that helps anymore I am at a loss but still plugging away :)A little attention to code formatting could bring some sanity to yourself. Enclosing that formatted code in the code tags on this forum would bring a lot of sanity to those trying to help you:
    select l.location_no
    ,      l.zone_code
    ,      la.area_code
    from move.location l
    ,    move.location_area la
    where la.location_no = l.location_no
          l.zone_code = 'Z=BIN'
    and   la.area_code != 'DA-REPL'
    order by 1And once it is formatted for easier reading by humans, it's easier to see that you are missing an "and" (maybe "or"?) in your WHERE clause.

  • Please Help in query

    SELECT PEE2.ASSIGNMENT_ID,--,PEEV2.EFFECTIVE_START_DATE,
    PET.ELEMENT_NAME,NVL(MAX(PEEV2.SCREEN_ENTRY_VALUE),0)SALARY
    --PEE2.EFFECTIVE_START_DATE PEE_START
    FROM PAY_ELEMENT_ENTRIES_F PEE2,PAY_ELEMENT_ENTRY_VALUES_F PEEV2 , PAY_ELEMENT_TYPES_F PET
    WHERE PEE2.ELEMENT_TYPE_ID = PET.ELEMENT_TYPE_ID
    AND PEE2.ELEMENT_ENTRY_ID=PEEV2.ELEMENT_ENTRY_ID
    AND PET.ELEMENT_NAME IN('BASIC_SALARY','AL_CONVEYANCE','AL_TEA','AL_COLA')
    AND PEEV2.SCREEN_ENTRY_VALUE IS NOT NULL
    AND (PEE2.ASSIGNMENT_ID,PEEV2.EFFECTIVE_START_DATE)=(
    SELECT PEE.ASSIGNMENT_ID,MAX(PEEV.EFFECTIVE_START_DATE)
    FROM PAY_ELEMENT_ENTRIES_F PEE,PAY_ELEMENT_ENTRY_VALUES_F PEEV
    WHERE PEE.ELEMENT_ENTRY_ID=PEEV.ELEMENT_ENTRY_ID
    AND PEE.ASSIGNMENT_ID=:ASSIGNMENT_ID
    AND PEE.ELEMENT_TYPE_ID = PET.ELEMENT_TYPE_ID
    AND PET.ELEMENT_NAME IN('BASIC_SALARY','AL_CONVEYANCE','AL_TEA','AL_COLA')
    AND PEEV.SCREEN_ENTRY_VALUE IS NOT NULL
    GROUP BY PEE.ASSIGNMENT_ID
    )GROUP BY ASSIGNMENT_ID , PET.ELEMENT_TYPE_ID , PET.ELEMENT_NAME
    output is
    ASSIGNMENT_ID     ELEMENT_NAME     SALARY
    117     AL_COLA     650
    117     AL_CONVEYANCE     1180
    117     AL_TEA     172
    117     BASIC_SALARY     7820
    but i want the output like this
    ASSIGNMENT_ID ------AL_COLA------AL_CONVEYANCE------AL_TEA-------BASIC_SALARY
    117---------------------------650-------------------1180----------------------172-----------7820
    PLZZ HELP NO HARDCODE PLZZ ONLY DYNAMIC QUERY REQUIRED AND NO PL/SQL USED..
    REGARDS
    RANCHOO

    Hi,
    Since you didn't post any tables, I'll use the scott.emp table to show you how to get results like that.
    Let's say we're interested in this data:
    SELECT       deptno
    ,       job
    ,       sal
    FROM       scott.emp
    ORDER BY  deptno
    ,     job
        DEPTNO JOB              SAL
            10 CLERK           1300
            10 MANAGER         2450
            10 PRESIDENT       5000
            20 ANALYST         3000
            20 ANALYST         3000
            20 CLERK           1100
            20 CLERK            800
            20 MANAGER         2975
            30 CLERK            950
            30 MANAGER         2850
            30 SALESMAN        1250
            30 SALESMAN        1250
            30 SALESMAN        1600
            30 SALESMAN        1500Let's say we want to get a total sal for each deptno and job, aned present it as a cross-tab, with a row for every deptno and a column for every job. As Karthick pointed out, that requires dynamic SQL, so let's just take the first 4 jobs in alphabetic order. The query below numbers the jobs 1, 2, 3, ... in alphabetic order, then uses that number to consider only a certain job in each column.
    WITH     got_jnum    AS
         SELECT       deptno
         ,       job
         ,       sal
         ,       DENSE_RANK () OVER (ORDER BY job)     AS jnum
         FROM       scott.emp
    SELECT       deptno
    ,       TO_CHAR (SUM (CASE WHEN jnum = 1 THEN sal END), '99999999')     AS job_1
    ,       TO_CHAR (SUM (CASE WHEN jnum = 2 THEN sal END), '99999999')     AS job_2
    ,       TO_CHAR (SUM (CASE WHEN jnum = 3 THEN sal END), '99999999')     AS job_3
    ,       TO_CHAR (SUM (CASE WHEN jnum = 4 THEN sal END), '99999999')     AS job_4
    FROM       got_jnum
    GROUP BY  deptno
        UNION ALL
    SELECT       NULL                                   AS deptno
    ,       MIN (CASE WHEN jnum = 1 THEN LPAD (job, 9) END)     AS job_1
    ,       MIN (CASE WHEN jnum = 2 THEN LPAD (job, 9) END)     AS job_2
    ,       MIN (CASE WHEN jnum = 3 THEN LPAD (job, 9) END)     AS job_3
    ,       MIN (CASE WHEN jnum = 4 THEN LPAD (job, 9) END)     AS job_4
    FROM       got_jnum
    ORDER BY  deptno     NULLS FIRST
        DEPTNO JOB_1     JOB_2     JOB_3     JOB_4
                 ANALYST     CLERK   MANAGER PRESIDENT
            10                1300      2450      5000
            20      6000      1900      2975
            30                 950      2850A lot of the complexity in the query above involves getting the row with the actual job names. If you knew what they were, you could hard-colde them into the query; then you woldn't need the second part of the UNION, and therefore you wouldn't need TO_CHAR.
    This is called a Pivot . Search for "Pivot" (or, as Karthick suggested "Rows to Columns") to see more examples and explanations.
    If you really want a variable number of columns, then you need dynamic SQL, as Karthick explained. This isn't very hard, as dynamic SQL goes. You just need to have a preliminary query determine what the jobs are, and write an appropriate SUM expression (with column alias) to use in the SELECT clause. See [this thread|http://forums.oracle.com/forums/message.jspa?messageID=3227306] for an example.
    Another way to get a variable number of jobs is to use String Aggregation , where all the data about all the jobs is combined in one giant string column. That huge string can be formatted so that it looks like separate columns. [This site|http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php] has a good summary of different String Aggregation techniques.

  • Please help - Recursive Query Restrictions

    Hi All,
    I wanted to know what restrictions are placed on Oracle Recursive Query capability. Any help or links in this regards would be highly appreciated. Waiting to hear from you.
    Thanks,
    Snehal

    Can't think of anything I would term a restriction off the top of my head. There are a few notes in the SQL Reference about precedence that probably aren't obvious.
    Are you having a particular problem with this syntax?
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Please help with query

    Hello, I'm trying to write a query which is of the form below:
    select (aa.name || bb.name) full_name
    from
    (select * from per_positions where name = 'Igwe') aa,
    (select * from per_positions where name = 'OSHS.Application.Specialist.Head Office') bb
    There are two generated tables aa and bb. Sometimes aa and bb both return a value and sometimes only aa or only bb returns a value. So my question is, in a scenario where only of the inner tables returns a value, is it possible to make the other table return a null or blank value? In my case, when one of the tables doesn't return a value the entire record shows a null value. Thanks.

    user FULL JOIN
    SQL> with t
      2  as
      3  (select 'a' name from dual
      4  union all
      5  select 'b' name from dual
      6  )
      7  select aa.name||bb.name
      8    from (select name from t where name = 'a') aa
      9    full join (select name from t where name = 'b') bb
    10      on 1=1
    11  /
    AA
    ab
    SQL> with t
      2  as
      3  (select 'a' name from dual
      4  union all
      5  select 'b' name from dual
      6  )
      7  select aa.name||bb.name
      8    from (select name from t where name = 'a') aa
      9    full join (select name from t where name = 'x') bb
    10      on 1=1
    11  /
    AA
    a
    SQL> with t
      2  as
      3  (select 'a' name from dual
      4  union all
      5  select 'b' name from dual
      6  )
      7  select aa.name||bb.name
      8    from (select name from t where name = 'x') aa
      9    full join (select name from t where name = 'b') bb
    10      on 1=1
    11  /
    AA
    b

  • Help With Query Performance

    Hi Everyone,
    I have to query a table that stores daily information and I only need to get the current month's data out of there. There is A LOT of data in there (4 years X 15 stores X 65 depts). I was wondering if there was a way to get the current month's data fast. Now it's extremely slow, 5 mins to query, and my users can't wait that long.
    Any sugguestions
    Thank You
    -Sam

    Assuming that emp_id is the PK of emp, then you do not need the MAX on the data from emp. Also you really do not need to put conditions against sysdate. If you only want the records for the current month, then this should work:
    SELECT TO_CHAR(cms_bh_dagent.row_date, 'mm/yyyy') row_date,
           emp.id, emp.short_name, emp.dept_code, emp.descr,
           SUM(cms_bh_dagent.ti_stafftime) AS ti_stafftime,
           SUM(cms_bh_dagent.ti_availtime) AS ti_availtime,
           SUM(cms_bh_dagent.acdcalls) AS acdcalls,
           SUM(cms_bh_dagent.acdtime) AS acdtime,
           SUM(cms_bh_dagent.acwtime) AS acwtime,
           SUM(cms_bh_dagent.holdcalls) AS holdcalls,
           SUM(cms_bh_dagent.holdtime) AS holdtime,
           SUM(cms_bh_dagent.ti_auxtime0) AS ti_auxtime0
    FROM cms_bh_dagent
            INNER JOIN emp ON cms_bh_dagent.logid = emp.acd_login_id
    WHERE cms_bh_dagent.row_date BETWEEN TRUNC(sysdate, 'MONTH') AND
                                         LAST_DAY(TRUNC(sysdate)) and
          emp.code = :tlcode
    GROUP BY TO_CHAR(cms_bh_dagent.row_date, 'mm/yyyy'),
             emp.id, emp.short_name, emp.dept_code, emp.descrIt seems to me that an index on emp.code might be useful in this query, as well as one on cms_bh_dagent (logid , row_date).
    If you want to be able to specify the from and to date, then replace the predicate on cms_bh_dagent.row_date with:
    BETWEEN TO_DATE(start_date, 'your_format') AND TO_DATE(end_date, 'your_format')
    HTH
    John

  • Please help -- MySQL Query to Oracle

    I have been trying to convert the following MySQL query to work with Oracle 9i. There seem to be two problems:
    1) Oracle doesn't like the inclusion of the tblpackagegeneral.packageid in the "ON" clause of the "JOIN".
    2) The "GROUP BY" only has the one field, "tblpackagegeneral.packageid", specified; Oracle wants the other two specified as well. When I do that I get a different data set than what MySQL returns for the same tables of data: specifically MySQL returns one row for each packageid but the revised Oracle version returns more than 1 sometimes.
    I would appreciate any assistance possible.
    /* Formatted on 2003/07/07 14:43 (Formatter Plus v4.8.0) */
    SELECT tblpackagegeneral.packageid,
    CASE
    WHEN NVL
    (COUNT (tblpackagelearnerassignment.learnerid),
    COUNT (tbllearnergeneral.learnerid)
    ) > 0
    THEN 'Activity'
    WHEN tbllearnergeneral.subscribetopubliccourse = 'true'
    AND tblpackagegeneral.packageaccess = 'Public'
    THEN 'ActivityAfterSubscribe'
    WHEN ( tbllearnergeneral.subscribetopubliccourse = 'false'
    AND tblpackagegeneral.packageaccess = 'Public'
    THEN 'Subscribe'
    ELSE 'Subscribe'
    END AS "ASSIGNSTATUS"
    FROM tblpackagegeneral, tbllearnergeneral LEFT OUTER JOIN tblpackagelearnerassignment ON ( tblpackagelearnerassignment.packageid =
    tblpackagegeneral.packageid
    AND tblpackagelearnerassignment.learnerid =
    tbllearnergeneral.learnerid
    WHERE tbllearnergeneral.learnerid = '%var'
    AND tblpackagegeneral.packageavailability = 'Available'
    AND TO_CHAR (tblpackagegeneral.dateto, 'YYYYMMDD') >=
    TO_CHAR (CURRENT_TIMESTAMP, 'YYYYMMDD')
    GROUP BY tblpackagegeneral.packageid;
    Sincerely,
    Bill Robinson

    I have been trying to convert the following MySQL query to work with Oracle 9i. There seem to be two problems:
    1) Oracle doesn't like the inclusion of the tblpackagegeneral.packageid in the "ON" clause of the "JOIN".
    2) The "GROUP BY" only has the one field, "tblpackagegeneral.packageid", specified; Oracle wants the other two specified as well. When I do that I get a different data set than what MySQL returns for the same tables of data: specifically MySQL returns one row for each packageid but the revised Oracle version returns more than 1 sometimes.
    I would appreciate any assistance possible.
    /* Formatted on 2003/07/07 14:43 (Formatter Plus v4.8.0) */
    SELECT tblpackagegeneral.packageid,
    CASE
    WHEN NVL
    (COUNT (tblpackagelearnerassignment.learnerid),
    COUNT (tbllearnergeneral.learnerid)
    ) > 0
    THEN 'Activity'
    WHEN tbllearnergeneral.subscribetopubliccourse = 'true'
    AND tblpackagegeneral.packageaccess = 'Public'
    THEN 'ActivityAfterSubscribe'
    WHEN ( tbllearnergeneral.subscribetopubliccourse = 'false'
    AND tblpackagegeneral.packageaccess = 'Public'
    THEN 'Subscribe'
    ELSE 'Subscribe'
    END AS "ASSIGNSTATUS"
    FROM tblpackagegeneral, tbllearnergeneral LEFT OUTER JOIN tblpackagelearnerassignment ON ( tblpackagelearnerassignment.packageid =
    tblpackagegeneral.packageid
    AND tblpackagelearnerassignment.learnerid =
    tbllearnergeneral.learnerid
    WHERE tbllearnergeneral.learnerid = '%var'
    AND tblpackagegeneral.packageavailability = 'Available'
    AND TO_CHAR (tblpackagegeneral.dateto, 'YYYYMMDD') >=
    TO_CHAR (CURRENT_TIMESTAMP, 'YYYYMMDD')
    GROUP BY tblpackagegeneral.packageid;
    Sincerely,
    Bill Robinson

  • Please help, simple query not working

    Have the following script that I would like to run at multiple sites and create table columns if necessary:
    DECLARE
    table_name VARCHAR2 (30) := 'SITE_STATISTICS';
    column_name VARCHAR2 (30) := 'SITE_MONTH';
    column_data_type VARCHAR2 (30) := 'DATE';
    column_count INTEGER;
    dynamic_sql VARCHAR2 (4000);
    BEGIN
    SELECT COUNT (1)
    INTO column_count
    FROM SYS.USER_TAB_COLUMNS utc
    WHERE utc.table_name = table_name AND utc.column_name = column_name AND utc.data_type = column_data_type;
    SYS.DBMS_OUTPUT.ENABLE (4000);
    IF column_count = 0 THEN
    dynamic_sql :=
    ALTER TABLE SITE_STATISTICS ADD (SITE_MONTH DATE);
    EXECUTE IMMEDIATE dynamic_sql;
    ELSE
    DBMS_OUTPUT.put_line ('Not running Dynamic Sql, found ' || column_count || ' corresponding rows in sys.user_tab_columns');
    END IF;
    END;
    EXIT;
    At a given site I do not have the given column, and running the select from sys.user_tab_columns manually returns 0 rows. However, when I run this script it outputs the following:
    Not running Dynamic Sql, found 128 corresponding rows in sys.user_tab_columns
    What's going on!?

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> create table abc (c1 number(10));
    Table created.
    SQL> DECLARE
      2     table_name1                   VARCHAR2 ( 30 ) := 'ABC';
      3     column_name1                  VARCHAR2 ( 30 ) := 'SITE_MONTH';
      4     column_data_type1             VARCHAR2 ( 30 ) := 'DATE';
      5     column_count                  INTEGER;
      6     dynamic_sql                   VARCHAR2 ( 4000 );
      7  BEGIN
      8     SELECT COUNT ( 1 )
      9       INTO column_count
    10       FROM SYS.user_tab_columns utc
    11      WHERE utc.table_name = table_name1
    12        AND utc.column_name = column_name1
    13        AND utc.data_type = column_data_type1;
    14  
    15     SYS.DBMS_OUTPUT.ENABLE ( 4000 );
    16  
    17     IF column_count = 0 THEN
    18  
    19        dynamic_sql :='ALTER TABLE ABC ADD (SITE_MONTH DATE,SHIP_CONTANK INTEGER,SHIP_CONRAIL INTEGER)';
    20  
    21        EXECUTE IMMEDIATE dynamic_sql;
    22     ELSE
    23        DBMS_OUTPUT.put_line (    'Not running Dynamic Sql, found '
    24                               || column_count
    25                               || ' corresponding rows in sys.user_tab_columns'
    26                             );
    27     END IF;
    28  END;
    29  /
    PL/SQL procedure successfully completed.
    SQL> desc abc
    Name                                      Null?    Type
    C1                                                 NUMBER(10)
    SITE_MONTH                                         DATE
    SHIP_CONTANK                                       NUMBER(38)
    SHIP_CONRAIL                                       NUMBER(38)

  • Please help SQL query

    why this works fine
    SELECT * FROM (
    SELECT ename,deptno,sal ,ROWNUM RN FROM emp)
    WHERE MOD(RN,3)=0
    while
    SELECT rownum FROM employees WHERE MOD(Rownum,3)=0
    wotnh works
    why this happenssssssssssssss

    ROWNUM is dynamically determined on-the-fly during the fetching of results.
    So this works:
    SELECT * FROM table WHERE rownum < 11
    It will return the first 10 rows. The following does not work:
    SELECT * FROM table WHERE rownum between 11 and 20
    As ROWNUM is added as the results are fetched from the database, it can only be used as a stopkey.
    To use ROWNUM as any other column in a predicate, you need to change ROWNUM from a "dynamic on-the-fly" column into a "proper" column. Just as you did with your 1st SELECT.
    E.g.WITH my_results AS(
            SELECT rownum AS RNO, o.* FROM all_objects o WHERE object_type = 'TRIGGER'
    SELECT
            object_id,
            object_name
    FROM    my_results
    WHERE   rno between 11 and 20

  • Help me query tunning

    Hi Guru's
    Can you please help me query tunning.
    Database Version : Oracle 11g - 11.2.0.3
    select  distinct  corporation_name custer_name,
            glog_util.remove_domain(SHIP_BUY.SERVPROV_GID ) SCAC,
            glog_util.remove_domain(ship_buy.shipment_gid) buy_shipment_gid,
            F_Get_SELL_ID_STRING(SHIP_BUY.SHIPMENT_GID) sell_shipment_gid,
            ship_buy.domain_name,    
            F_GET_ORDER_RELEASE_GID('B',SHIP_BUY.SHIPMENT_GID,0) ORDER_RELEASE_GID,
            f_get_refnum_string('SHIPMENT', ship_buy.shipment_gid, 'MBOL_NUMBER_CLEANSED')MBOL_NUMBER,
            F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) POD_RECEIVED_DATE,
            f_get_exp_accrue_amt(ship_buy.shipment_gid,'SHIPMENT') Total_accrual_amount    
    from shipment ship_buy,
            invoice inv,
            invoice_shipment si,
            --voucher v,
            corporation corp
    where corp.domain_name=ship_buy.domain_name
            and corp.is_domain_master='Y'
          and 1=1
          AND ship_buy.domain_name like 'UPS/CP/DFP/%'
          and F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
            --and V.INVOICE_GID(+) = inv.invoice_gid
            --and ship_buy.domain_name = 'UPS/CP/VZNB'
            and si.shipment_gid(+) = SHIP_BUY.SHIPMENT_GID
            AND SI.INVOICE_GID = INV.INVOICE_GID(+)
            and SHIP_BUY.INSERT_DATE > '1-JAN-2007'
            and SHIP_BUY.USER_DEFINED1_ICON_GID = 'ACCEPTED'
    UNION        
    select  distinct  corporation_name custer_name,
            glog_util.remove_domain(SHIP_BUY.SERVPROV_GID ) SCAC,
            glog_util.remove_domain(ship_buy.shipment_gid) buy_shipment_gid,
            F_GET_SELL_ID_STRING( SHIP_BUY.SHIPMENT_GID) sell_shipment_gid,
            ship_buy.domain_name,    
            F_GET_ORDER_RELEASE_GID('B',SHIP_BUY.SHIPMENT_GID,0) ORDER_RELEASE_GID,
            f_get_refnum_string('SHIPMENT', ship_buy.shipment_gid, 'MBOL_NUMBER_CLEANSED')MBOL_NUMBER,
            F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) POD_RECEIVED_DATE,
            f_get_exp_accrue_amt(inv.invoice_gid,'INVOICE') Total_accrual_amount  
    from shipment ship_buy,
            invoice inv,
            invoice_shipment si,
          -- voucher v,
            corporation corp
    where corp.domain_name=ship_buy.domain_name
            and corp.is_domain_master='Y'
            and 1=1
            AND ship_buy.domain_name like 'UPS/CP/DFP/%'
            and F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
          --AND INV.DOMAIN_NAME = 'UPS/CP/VZNB'
          --and V.INVOICE_GID(+) = inv.invoice_gid
            and si.shipment_gid(+) = SHIP_BUY.SHIPMENT_GID
            AND SI.INVOICE_GID = INV.INVOICE_GID(+)
            and SHIP_BUY.INSERT_DATE > '1-JAN-2007'
            and INV.USER_DEFINED1_ICON_GID = 'ACCEPTED'
    GROUP BY corporation_name,SHIP_BUY.SHIPMENT_GID,SHIP_BUY.SERVPROV_GID,ship_buy.domain_name,inv.invoice_gid
    ORDER BY CUSTER_NAME, BUY_SHIPMENT_GID;
    And I generated the execution plan :
    | Id  | Operation                          | Name                    | Rows  | Bytes | Cost (%CPU)| Time    |
    |  0 | SELECT STATEMENT                  |                        |    3 |  448 |  415  (2)| 00:00:05 |
    |  1 |  SORT UNIQUE                      |                        |    3 |  448 |  414  (87)| 00:00:05 |
    |  2 |  UNION-ALL                        |                        |      |      |            |          |
    |  3 |    NESTED LOOPS OUTER              |                        |    3 |  384 |    57  (0)| 00:00:01 |
    |*  4 |    HASH JOIN                      |                        |    3 |  294 |    54  (0)| 00:00:01 |
    |*  5 |      TABLE ACCESS BY INDEX ROWID  | SHIPMENT                |    3 |  195 |    40  (0)| 00:00:01 |
    |*  6 |      INDEX SKIP SCAN              | IND_SHIP_DOM_ICON      |    54 |      |    25  (0)| 00:00:01 |
    |*  7 |      TABLE ACCESS FULL            | CORPORATION            |    4 |  132 |    14  (0)| 00:00:01 |
    |*  8 |    INDEX RANGE SCAN              | IND_INVOICESHIP_SHP_GID |    1 |    30 |    1  (0)| 00:00:01 |
    |  9 |    HASH GROUP BY                  |                        |    1 |  192 |  356  (1)| 00:00:05 |
    |* 10 |    HASH JOIN                      |                        |    1 |  192 |  354  (1)| 00:00:05 |
    |  11 |      NESTED LOOPS                  |                        |      |      |            |          |
    |  12 |      NESTED LOOPS                |                        |    1 |  159 |  339  (0)| 00:00:05 |
    |  13 |        NESTED LOOPS                |                        |  145 | 13920 |  194  (0)| 00:00:03 |
    |  14 |        TABLE ACCESS BY INDEX ROWID| INVOICE                |  145 |  5220 |    49  (0)| 00:00:01 |
    |* 15 |          INDEX SKIP SCAN          | IDX_INV_TYP_ICON_NAM    |  145 |      |    17  (0)| 00:00:01 |
    |* 16 |        INDEX RANGE SCAN          | UK_INVOICE_SHIPMENT    |    1 |    60 |    1  (0)| 00:00:01 |
    |* 17 |        INDEX UNIQUE SCAN          | PK_SHIPMENT            |    1 |      |    1  (0)| 00:00:01 |
    |* 18 |      TABLE ACCESS BY INDEX ROWID  | SHIPMENT                |    1 |    63 |    1  (0)| 00:00:01 |
    |* 19 |      TABLE ACCESS FULL            | CORPORATION            |    4 |  132 |    14  (0)| 00:00:01 |
    Predicate Information (identified by operation id):
      4 - access("CORP"."DOMAIN_NAME"="SHIP_BUY"."DOMAIN_NAME")
      5 - filter("F_GET_POD_RECEIVED_DATE"("SHIP_BUY"."SHIPMENT_GID")<=TO_DATE(' 2013-07-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss') AND "SHIP_BUY"."INSERT_DATE">TO_DATE(' 2007-01-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss'))
      6 - access("SHIP_BUY"."USER_DEFINED1_ICON_GID"='ACCEPTED' AND "SHIP_BUY"."DOMAIN_NAME" LIKE
                  'UPS/CP/DFP/%')
          filter("SHIP_BUY"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%' AND
                  "SHIP_BUY"."USER_DEFINED1_ICON_GID"='ACCEPTED')
      7 - filter("CORP"."IS_DOMAIN_MASTER"='Y' AND "CORP"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%')
      8 - access("SI"."SHIPMENT_GID"(+)="SHIP_BUY"."SHIPMENT_GID")
      10 - access("CORP"."DOMAIN_NAME"="SHIP_BUY"."DOMAIN_NAME")
      15 - access("INV"."USER_DEFINED1_ICON_GID"='ACCEPTED')
          filter("INV"."USER_DEFINED1_ICON_GID"='ACCEPTED')
      16 - access("SI"."INVOICE_GID"="INV"."INVOICE_GID")
      17 - access("SI"."SHIPMENT_GID"="SHIP_BUY"."SHIPMENT_GID")
          filter("F_GET_POD_RECEIVED_DATE"("SHIP_BUY"."SHIPMENT_GID")<=TO_DATE(' 2013-07-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss'))
      18 - filter("SHIP_BUY"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%' AND "SHIP_BUY"."INSERT_DATE">TO_DATE('
                  2007-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      19 - filter("CORP"."IS_DOMAIN_MASTER"='Y' AND "CORP"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%')
    Statistics
        246247  recursive calls
              2  db block gets
        1660067  consistent gets
          13839  physical reads
              0  redo size
        592054  bytes sent via SQL*Net to client
          6024  bytes received via SQL*Net from client
            502  SQL*Net roundtrips to/from client
          15296  sorts (memory)
              0  sorts (disk)
          7513  rows processed

    Hmmm...why does this look familiar?
    F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
    SHIP_BUY.INSERT_DATE > '1-JAN-2007'
    Like I said in your other thread about this, these two lines need to be fixed and your function needs to be fixed so the return statement doesn't do an implicit date conversion.
    Can't you see what that first line is doing?  You're taking a character string, turning it into a date, then back to a character string.
    If nothing else, these lines should be...
    F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_date('31-JUL-2013', 'DD-MON-YYYY')
    SHIP_BUY.INSERT_DATE > to_date('01-JAN-2007','DD-MON-YYYY')
    (assuming insert_date is a proper date format, fingers crossed)

Maybe you are looking for