Need help in re-writing a query

SELECT DDQ.DS_PRS_ID,TO_CHAR(DDQ.DEACTIVATE_DT,'DD-MON-YYYY HH24:MI'),
TO_CHAR(SYSDATE+NVL(L.GMT_OFFSET,0)/24,'DD-MON-YYYY HH24:MI'),
PCWI.PRS_ID,mcr_pkg_hra_person_name.get_tc_full_name(PCWI.prs_last_nm,
PCWI.prs_first_nm,PCWI.prs_middle_init,PCWI.prs_pref_nm,
PCWI.ROLE_TYPE_CD),TO_CHAR(PCWI.termn_dt,'DD-MON-YYYY HH24:MI'),
MOF.OFFER_STATUS_CD, TO_CHAR(NVL(MOF.ADJ_START_DT,START_DT),'DD-MON-YYYY HH24:MI'),
TO_CHAR(OFFER_STATUS_DT, 'DD-MON-YYYY HH24:MI') /* Added by Ashwin for Radar 3160778 */
FROM MER_OFFER_FORM MOF, LOC L, PRS_CUR_WORK_INFO PCWI, DS_DEACTIVATE_QUEUE DDQ
WHERE DDQ.DS_PRS_ID > 0
AND PCWI.DS_PRS_ID = DDQ.DS_PRS_ID
AND L.LOC_CD = PCWI.LOC_CD
AND MOF.DS_PRS_ID(+) = PCWI.DS_PRS_ID;
The above gives the following output.
4519     29-NOV-2006 23:59     18-DEC-2007 19:33     14626     Larson, Marianne     29-NOV-2006 00:00     10     01-SEP-2007 00:00     03-DEC-2007 15:41
4519     29-NOV-2006 23:59     18-DEC-2007 19:33     14626     Larson, Marianne     29-NOV-2006 00:00     10     11-MAR-1998 00:00     19-MAR-1998 16:51
130516250     26-JAN-2007 23:59     C429219     18-DEC-2007 19:39     *GIROUX, DAVID A.          10     19-AUG-2006 00:00     15-AUG-2006 15:45
130516250     26-JAN-2007 23:59     C429219     18-DEC-2007 19:39     *GIROUX, DAVID A.          10     11-JUN-2006 00:00     09-JUN-2006 15:27
I want to select distinct DDQ.DS_PRS_ID and minmum OFFER_STATUS_DT among the duplicate DDQ.DS_PRS_ID.
I somehow want to avoid duplicate DDQ.DS_PRS_ID here (Distinct clause does not work. And we cant remove outer join condition from the above query).
Could you please suggest me the query for this?
Regards,
Chandra Bhushan Bakshi

Can you not just do something like
SELECT ddq.ds_prs_id, TO_CHAR (ddq.deactivate_dt, 'DD-MON-YYYY HH24:MI'),
       TO_CHAR (SYSDATE + NVL (l.gmt_offset, 0) / 24, 'DD-MON-YYYY HH24:MI'),
       pcwi.prs_id,
       mcr_pkg_hra_person_name.get_tc_full_name (pcwi.prs_last_nm,
                                                 pcwi.prs_first_nm,
                                                 pcwi.prs_middle_init,
                                                 pcwi.prs_pref_nm,
                                                 pcwi.role_type_cd
       TO_CHAR (pcwi.termn_dt, 'DD-MON-YYYY HH24:MI'), mof.offer_status_cd,
       TO_CHAR (NVL (mof.adj_start_dt, start_dt), 'DD-MON-YYYY HH24:MI'),
       TO_CHAR (offer_status_dt, 'DD-MON-YYYY HH24:MI')
  FROM mer_offer_form mof,
       loc l,
       prs_cur_work_info pcwi,
       ds_deactivate_queue ddq
WHERE ddq.ds_prs_id > 0
   AND pcwi.ds_prs_id = ddq.ds_prs_id
   AND l.loc_cd = pcwi.loc_cd
   AND mof.ds_prs_id(+) = pcwi.ds_prs_id
   AND mof.offer_status_dt(+) = (select min(offer_status_dt)
                                 from mer_offer_form mof2
                                 where ds_prs_id = ddq.ds_prs_id)

Similar Messages

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • Pls help me in writing a query for my problem !

    I have to find out the amount(LAmt) for members who lie btw diff age groups, below are the table structures:
    table1
    DOB ID
    12/24/1986 F125
    06/05/1988 F223
    05/04/1987 F589
    07/07/2001 F856
    table2
    LAmt ID LDate
    $56 F125 01/01/2011
    $45 F223 08/22/2005
    $87 F589 09/24/2004
    $87 F856 10/10/2000
    $87 F587 09/09/2002
    Query:
    1) I have to find the age group for the members who lie between 1 to 5 & 6 to 10 and so on, Also find the the no. of days since they have been registered(Using LDate-Current Date) , also the LAmt for those members.

    Hi,
    836810 wrote:
    SELECT -- To calculate Listed Amount of members btw age group 0 to 4
    COUNT(DateOfBirth) as Nopresent,
    DATEDIFF (yyyy,DateOfBirth,GETDATE()) as age,
    SUM(RPTInvHosp.AccountListAmount) as ListedAmt,
    COUNT(DateOfBirth) * SUM(RPTInvHosp.AccountListAmount) as [Calc]
    FROM RPTInv1st,RPTInvHosp
    WHERE
    DATEDIFF (yyyy,DateOfBirth,GETDATE()) >= 0 and
    DATEDIFF (yyyy,DateOfBirth,GETDATE()) < 5 and
    RPTInv1st.PASDebtorID=RPTInvHosp.PASDebtorID
    Group by DATEDIFF (yyyy,DateOfBirth,GETDATE())
    I want to get members btw the particular age group JOIN with the no of days they have been opened an account & their amount.In Oracle, use double-quotes (or nothing) instead of square brackets around aliases:
    COUNT(DateOfBirth) * SUM(RPTInvHosp.AccountListAmount)  as "Calc"The double-quotes are only necessary if you want the alias not to conform to the normal naming conventions; they are optional around normal names, such as CALC.
    There are no built-in functions called GETDATE or DATEDIFF in Oracle.
    In Oracle, SYSDATE returns the current DATE (on the database server).
    There's nothing very convenient in Oracle for getting the difference between two DATEs in units of a year. The best way is to use MONTHS_BETWEEN to get the difference in months, and then divide that number by 12, like this:
    WHERE     FLOOR ( MONTHS_BETWEEN ( SYSDATE
                                , DateOfBirth
               / 12
               )          BETWEEN     0
                         AND     4Do you need help about how to do a join?
    It's not at all clear what you want here.
    Whenever you have a question, post CREATE TABLE and INSERT statements for your sample data, and post the exact results you want from that data. Explain, with specific examples, how you get those results from that data.
    Always say what version of Oracle (or other software) you're using.

  • Need help inLOV's in AF Query

    Hi,
    I need help in adding LOV's in AF Query. Please do the need full.
    Regards,

    Hi all,
    My issue was resolved i have followed the link"http://andrejusb.blogspot.com/2008/11/adf-query-component-and-view-criteria.html"
    Regards,

  • Need help in PO Approval Group Query

    Hi,
    I need a Query which will list of users that has the Approval Group “BUYER” and “BUYER_DEMO” assigned to them.
    It will be needful if anyone provides me the Query
    Thanks and Regards

    Hi
    Try this.
    SELECT PAPF.employee_number
    ,PAPF.full_name
    FROM po_control_groups_all PCGA
    ,po_position_controls_all PPCA
    ,per_all_assignments_f PAAF
    ,per_all_people_f PAPF
    WHERE PCGA.control_group_name IN ('BUYER','BUYER_DEMO')
    AND PCGA.control_group_id = PPCA.control_group_id
    AND PPCA.position_id = PAAF.position_id
    AND PAAF.person_id = PAPF.person_id
    Thanks and Regards,
    JD

  • Need Help In Solving Writing To Queue Problem

    Hi Guys,
    I have two threads that are adding to the same message queue. The first one is suppose to add four integers consecutively. Meanwhile the second thread add an integer in between the four integers. Because of that my application is not working properly. I would like that when a thread is adding then the other must wait before it adds. The method that the threads call to add to the queue are all synchronized, but it is still behaving like that.
    I need help in solving it.
    Thanks.
    Edited by: kap on Aug 9, 2010 5:22 AM

    kap wrote:
    Please what do you mean by synchronizing on the same object? Can you explain it to me?
    When you synchronize a block of Java code, you synchronize on a particular object, which is called the Monitor.
    The effect is only to prevent another thread running this, or another block of code synchronized on the same object.
    If you use synchronized methods, then the monitor is the object to which the method belongs (or the class if the method is static). The same synchronized method can be executed simultaneously on a different instance of the object.

  • Need help to re-format the query

    Hi All,
    Could any one please help me to rewrite this query or explain me how to do it as it is taking 20 mins to execute....
    SELECT
    AC.ACC_NO||DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.PAYMENT_SET      
                                       FROM
            MIF LMI2 WHERE LMI2.MID =
            (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID= MI.MID AND RELATION='ROF')),MI.PAYMENT_SET)||
            DECODE(MI.MSG_CLASS,'ROF', (SELECT LMI2.SERVICE FROM MIF LMI2 WHERE LMI2.MID = (SELECT CHILDMID FROM
      MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),MI.SERVICE) HASH_KEY,
      MI.MID ,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.PAYMENT_SET FROM MIF LMI2
      WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
      RELATION='ROF')),MI.PAYMENT_SET) PAYMENT_SET,
      MI.AMOUNT,
      NVL(DECODE(MI.MSG_CLASS,'ROF',MI.CRAMOUNT, MI.DBAMOUNT) ,0) AMT,
      AC.ACC_NO,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.BATCH_COMPANY_CD FROM MIF LMI2 WHERE
      LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
      RELATION='ROF')),MI.BATCH_COMPANY_CD) BATCHCOMP,
      AC.ACC_ALIAS, NVL(AC.IBAN,
      NVL(AC.ACC_ALIAS,AC.ACC_NO)) IBAN_ACCNO,
      AC.CURRENCY , AC.ACCOUNTNAME ,
      CASE
           WHEN (SIGN(MI.PROCESS_DT - TO_DATE(:B2 ,'YYYYMMDD'))) = '1'
           THEN 'F'
           ELSE 'C' END FUTURE_IND,
           (CASE
                WHEN (MI.MSG_STATUS = 'CANCELED' OR   MI.STATBFHELD = 'CANCELED')
                THEN 'C'
                WHEN MI.BATCH_PAYMENT_TP = 'RMTRT'
                THEN 'R'
                WHEN (MI.REJECT_RETURN='REJT' OR MI.MSG_CLASS = 'ROF' OR MI.MSG_STATUS = 'REJECTED')
                THEN 'A'
                WHEN (MI.REJECT_RETURN='RETN' OR (MI.BATCH_PAYMENT_TP='RTACH' AND MSG_CLASS='ROF'))
                THEN 'B'
                WHEN  MI.MSG_STATUS='FORWARD_PROCESSING'
                THEN 'F'
                WHEN (MI.MSG_STATUS NOT IN  ('COMPLETE','CANCELED','REJECTED') OR (MI.MSG_STATUS='AGED' AND
                     MI.STATBFHELD NOT IN ('COMPLETE','CANCELED','REJECTED')) )
                THEN 'U'
                WHEN  MI.PROCESS_DT = TO_DATE(:B2 ,'YYYYMMDD')
                THEN 'P' END)
      PAY_STATUS,
      MT.DB_FEE_ACCOUNT_CCY,
      (SELECT MESSAGEFREETEXT.CONTENTS
           FROM
           MESSAGEFREETEXT
           WHERE
                FIELDNAME ='MANDATEREFERENCE'
                     AND MESSAGEFREETEXT.MID= MI.MID) MANDREF,
      (SELECT MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT
           WHERE FIELDNAME ='DIRECT_DEBIT_REFERENCE' AND MESSAGEFREETEXT.MID=MI.MID)  DDREF,
      MT.CUSTOMER_BATCH_REFERENCE LOCINFO,
      (SELECT  MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT WHERE FIELDNAME =  'SECOND_PARTY_ID' AND MESSAGEFREETEXT.MID=MI.MID) SECPRTYINF,
      (SELECT  MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT WHERE FIELDNAME = 'HUB_PAY_PROD_TYP' AND MESSAGEFREETEXT.MID=MI.MID) PAYPRODTYP,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.CHANNEL_REFERENCE FROM MIF LMI2
                          WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
                                         RELATION='ROF')),MI.CHANNEL_REFERENCE) CHNREF,
      (SELECT  MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT
           WHERE FIELDNAME =  'CHN_BATCH_REF' AND MESSAGEFREETEXT.MID=MI.MID) CHNBATREF,
      TO_CHAR(DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.VALUE_DATE FROM MIF LMI2
                     WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
                                    RELATION='ROF')),MI.VALUE_DATE),'DD/MM/YYYY') VALUEDT,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.ORIG_REFERENCE FROM MIF LMI2 WHERE LMI2.MID = (SELECT
                          CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),
                                                        MI.ORIG_REFERENCE) ORIGREF,
      CASE
           WHEN (MI.OFFICE <> MI.ORIG_OFFICE)
           THEN MT.DR_SIDE_RATE_AM
           ELSE
                CASE
                     WHEN MI.DBCURRENCY = MI.CRCURRENCY
                     THEN
                          CASE
                               WHEN MI.CRCURRENCY = :B4
                               THEN MT.DR_RATE ELSE MT.CR_RATE
                          END
                     ELSE
                          CASE
                               WHEN   MI.CRCURRENCY = :B4
                               THEN MT.DR_RATE ELSE MT.CR_RATE
                          END
                END
           END EXCHRT,
      MT.BBK_ADDR1,
      MT.BBK_ADDR2,
      MT.BBK_ADDR3 ,
      MT.BBK ,
      MT.BNF_ADDR1,
      MT.BNF_ADDR2,
      MT.BNF_ADDR3,
      MT.BNF_ADDR4 ,
      MT.BNF ,
      DECODE(MT.BNF_IDCODE,'AC',MT.BNF_ID,' ') ORGBNFID,
      DECODE(NVL(MI.ORIG_INSTRUCT_AMOUNT,0),0, MI.ORIG_AMOUNT) ORGINSTAMT,
      NVL(TRIM(MI.ORIG_INSTRUCT_CURRENCY),  MI.ORIG_CURRENCY) ORGINSTCUR,
      CASE
           WHEN MOP LIKE 'DRFT%'
           THEN 'DD'
           WHEN MOP   LIKE 'CHEQ%'
           THEN 'CO'
           WHEN MOP LIKE 'SWIFT'
           THEN 'TT'
           WHEN MOP LIKE 'DDP%'
           THEN 'T'
           WHEN MOP LIKE 'BOOK'
           THEN 'T' ELSE 'LP'
      END PYMTTP,
      MT.OBI ,
      TO_CHAR(MI.PROCESS_DT,'YYYYMMDD') PROCESSDT,
      MI.REFERENCE,
      MT.BBK_BIC,
      MT.BBK_IDCODE,
      DECODE(MT.BBK_IDCODE,'AC',' ',SUBSTR(MT.BBK_ID,1,12)) BBKID,
      MI.LOCAL_REF,
      MI.CURRENCY INDCURR,
      MI.MSG_STATUS,
      MI.PK_BATCH_SUBSET,
      TO_CHAR(SBBATCH.PROCESS_DT,'YYYYMMDD') SBPROCESSDT,
      DECODE(MI.MSG_CLASS,'ROF',MI.CRCURRENCY, MI.DBCURRENCY) DBCURR,
      MI.ORIG_REFERENCE ORIGREFRET
      FROM
           MIF MI,
           MTF1000 MT,
           ACCOUNTS AC,
           (     SELECT
                     MF.PK_BATCH_SUBSET,
                     MF.PROCESS_DT,
                     MTF.ORG_ID,
                     MTF.MP_CR_ACC,
                     MTF.CR_ACC_NO
                FROM
                     MIF MF,
                     MTF1000
                     MTF
                WHERE
                     ((MSG_STATUS IN ('COMPLETE','CANCELED','REJECTED')) OR
                     (MSG_STATUS = 'AGED' AND STATBFHELD IN ('COMPLETE','CANCELED','REJECTED')))
                AND
                     BATCH_MSG_TP = 'S' AND MF.MID = MTF.MID )
           SBBATCH
      WHERE
           MI.MSG_TYPE =   :B3
      AND MI.PROCESS_DT = TO_DATE(:B2 ,'YYYYMMDD')
      AND MI.BATCH_MSG_TP = 'I'
      AND DECODE(MI.MSG_CLASS,'ROF',
           (SELECT LMI2.SERVICE FROM MIF LMI2 WHERE LMI2.MID =
           (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),MI.SERVICE)
           IN ('NET','HCN','BIB','LST','MRI')
      AND MI.PK_BATCH_EXCH IN (SELECT PK_BATCH_EXCH FROM BATCH_EXCH)
      AND MI.MID = MT.MID
      AND SBBATCH.PK_BATCH_SUBSET = MI.PK_BATCH_SUBSET
      AND TRIM(DECODE(MI.MSG_CLASS,'ROF',MT.CR_ACC_NO, NVL(MT.ORG_ID,NVL(MT.MP_DB_ACC,MT.ACC_NO))) )=AC.ACC_NO
      AND AC.OFFICE = :B1
      ORDER BY HASH_KEY,PAY_STATUS

    Hi,
    please try this.
    The first decode or at least part of it repeats at least 7 times.
         DECODE(MI.MSG_CLASS,'ROF',
                                         (SELECT LMI2.PAYMENT_SET  
                                    FROM MIF LMI2 WHERE LMI2.MID =
          (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')
                                            ),MI.PAYMENT_SET
                   ||
        DECODE(MI.MSG_CLASS,'ROF',
                                         (SELECT LMI2.SERVICE
                                                                                 FROM MIF LMI2 WHERE LMI2.MID =
                   (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')
                                             ),MI.SERVICE) HASH_KEY,
    is similar to this
    select mif.* from mif, mfamily where mif.mid=mfamily.childmid
    and relation = 'ROF' and msg_class='ROF'
    insert it as an inline view and add a conditition
    from ...
    (select mif.* from mif, mfamily where mif.mid=mfamily.childmid
    and relation = 'ROF' and msg_class='ROF') rof
    Where ...
    and mi.mid=Rof.mid (+)...
    and your code above would look like
    nvl(rof.payment_set,mi.payment_set) || nvl(rof.service,mi.service) HASH_KEY,
    nvl(rof.payment_set,mi.payment_set) PAYMENT_SET
    replace all the same decode above with corresponding nvl(...)Hope this helps.

  • Need help on Regular expression and query

    Hi Guru's, Hope you all are doing great!.
    I have a scenario's where i need do insert the data into table.
    I have three scenarios :
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    Alex Romano
    Kodali,Raj,S
    pppppNow what i want is .
    1. Alex Romano
    if there is space between the string then i want to insert into first name and last name columns
    2. Kodali,Raj,S
    if its a comma between the string then i want to insert into last name , first name and middle name
    3. if there is only one string then same insert into first name and last name.
    I wrote the query earlier to handle only comma and now i am trying but not able to use this all scenarios
    Can you please help me out.
    WITH t AS (
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c))
    from
      SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
              , max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
              , max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME      
       FROM   t
      CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
      GROUP BY str
    ) ;Currently i am putting a b and c if its null.
    Thanks in advance!

    user590978 wrote:
    Hi Guru's, Hope you all are doing great!.
    I have a scenario's where i need do insert the data into table.
    I have three scenarios :
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    Alex Romano
    Kodali,Raj,S
    pppppNow what i want is .
    1. Alex Romano
    if there is space between the string then i want to insert into first name and last name columns
    2. Kodali,Raj,S
    if its a comma between the string then i want to insert into last name , first name and middle name
    3. if there is only one string then same insert into first name and last name.
    I wrote the query earlier to handle only comma and now i am trying but not able to use this all scenarios
    Can you please help me out.
    WITH t AS (
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c))
    from
    SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
    , max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
    , max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME      
    FROM   t
    CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
    GROUP BY str
    ) ;Currently i am putting a b and c if its null.
    Thanks in advance!It's never a popular suggestion, but why not fix the design to begin with?
    It's the year 2013, can a client not pass you a "complex" data structure consisting of first, middle and last name?
    Why rely on an unreliable construct when there are so many more usable way to achieve this?
    Cheers,

  • Need help in Report From SQL Query

    Hi All,
    I am facing a problem with a report. I need your help.
    I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
    If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
    I tried also increase the page time out in httpd.conf, but no use.
    The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
    Please help me to find appropriate reasone for the failure?

    user602513 wrote:
    Hi All,
    I am facing a problem with a report. I need your help.
    I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
    If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
    I tried also increase the page time out in httpd.conf, but no use.
    The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
    Please help me to find appropriate reasone for the failure?Do you get any errors or warnings or it is just the slow speed which is the issue?
    There could be a variety of reasons for the delayed processing of this report. That includes parameter settings for that page, cache settings, network configurations, etc.
    - explore best optimization for your query;
    - evaluate portal for best performance configuration; you may follow this note (Doc ID: *438794.1* ) for ideas;
    - third: for that particular page carrying that report, you can use caching wisely. browser cache is neither decent for large files, nor practical. instead, explore the page cache settings that portal provides.
    - also look for various log files (application.log and apache logs) if you are getting any warnings reflecting on some kind of processing halt.
    - and last but not the least: if you happen to bring up a portal report with more than 10000 rows for display then think about the usage of the report. Evaluate whether that report is good/useful for anything?
    HTH
    AMN

  • Need help in framing an SQL query

    Hi ,
    Requirement is that
    Let’s say I have a table say X
    I am passing two input params from UI and in DAO i am querying these input prams against the table X(has c1,c2 as columns ) (as it has two columns mapping the input params A,B from UI).
    if either one or Both of the input params matches ,only then i should fetch the records accordingly. It's understood that there won't be a scenario that both input params are null from UI.
    I have three conditions here,
    1.     A match against X, B doesnt Match
    2.     B match against X, A doesnt Match
    3.     Both A & B match against X
    if i use let's say,
    SELECT *FROM X WHERE (c1= A OR c2= B) .
    •     if A match against X B doesnt Match It is fetching all the records matching A - requirement fullfilled
    •     B match against X A doesnt Match It is fetching all the records matching B- requirement fullfilled.
    •     Both A & B match against X It is fetching all the records from the table matching the first condition (which here is A) . requirement not fullfilled.
    I am thinking of using the following query but I need to frame it in a way that based on ACHK & BCHK we need to add the conditions.
    SELECT CASE WHEN C1 = A THEN 0 ELSE 9 END AS ACHK, CASE WHEN C2 = B THEN 0 ELSE 9 END AS BCHK FROM X
    Based on ACHK & BCHK append the conditions. i.e.
    IF ACHK = 0 AND BCHK = 0 THEN
    AND C1 = A AND C2 = B
    ELSE
    AND (C1 = A OR C2 = B)
    Please help.

    Hi,
    963022 wrote:
    Would be glad if you can shed some light on role of DENSE_RANK here (ofcourse i did read the forums but i am confused on what basis a row is ranked).Complicated queries and expressions are usually built of smaller, simpler parts. To understand how the big, complicated thing works, look first at the smaller, simpler components of it, and make sure you understand how they work.
    In this case, the query is composed of a sub-query and a main query. Start by looking at the sub-query only. Display all rows and all columns of the sub-query.
    Break apart the complicated components of that sub-query. Rnk depends on an ORDER BY clause, but the expression used in that ORDER BY clause isn't displayed anywhere. Copy and display just that expression. (I called this case_1_2 in the query below.) Even that may be too complicated to understand, so break it apart. Case_1_2 is formed by adding 2 smaller CASE expressions; in the query below, I displayed each of the in separate columns (case_1 and case_2).
    So here's a query you might use to understand and debug the query I posted:
    WITH     targets          AS
         SELECT     'ABC' AS c1, 10 AS c2  FROM dual     UNION ALL
         SELECT     'ABC',          20            FROM dual     UNION ALL
         SELECT     'FOO',          10            FROM dual     UNION ALL
         SELECT     'FOO',          20            FROM dual     UNION ALL
         SELECT     'FOO',          99            FROM dual
    ,     got_rnk          AS
         SELECT     x.c1, x.c2
         ,     t.c1          AS target_c1
         ,     t.c2          AS target_c2
         ,     DENSE_RANK () OVER ( PARTITION BY  t.c1, t.c2
                                   ORDER BY          CASE
                                                 WHEN  x.c1  = t.c1
                                         THEN  1
                                         ELSE  0
                                             END
                                   + CASE
                                                 WHEN  x.c2  = t.c2
                                         THEN  2
                                         ELSE  0
                                             END
                             DESC
                           )          AS rnk
    --     *****  DEBUGGING SECTION  *****     The following columns are included only
    --                                       to see how the function above works.
         ,                               CASE
                                                 WHEN  x.c1  = t.c1
                                         THEN  1
                                         ELSE  0
                                             END
                                   + CASE
                                                 WHEN  x.c2  = t.c2
                                         THEN  2
                                         ELSE  0
                                             END           AS case_1_2
         ,                               CASE
                                                 WHEN  x.c1  = t.c1
                                         THEN  1
                                         ELSE  0
                                             END           AS case_1
         ,                            CASE
                                                 WHEN  x.c2  = t.c2
                                         THEN  2
                                         ELSE  0
                                             END           AS case_2
    --     *****  END OF DEBUGGING SECTION  *****
         FROM     targets  t
         JOIN           x  ON   x.c1     = t.c1
                       OR   x.c2     = t.c2
    --     The following main query is only for debugging
    SELECT       *
    FROM       got_rnk
    ORDER BY  target_c1, target_c2
    ,            rnk
    ;Output:
                  TARGET TARGET          CASE
    C1         C2 _C1       _C2    RNK   _1_2 CASE_1 CASE_2
    ABC        10 ABC        10      1      3      1      2
    ZZZ        10 ABC        10      2      2      0      2
    ABC         5 ABC        10      3      1      1      0
    ABC         6 ABC        10      3      1      1      0
    ABC         7 ABC        10      3      1      1      0
    ABC         1 ABC        10      3      1      1      0
    ABC         3 ABC        10      3      1      1      0
    ABC         2 ABC        10      3      1      1      0
    ABC         8 ABC        10      3      1      1      0
    ABC         9 ABC        10      3      1      1      0
    ABC         4 ABC        10      3      1      1      0
    ZZZ        20 ABC        20      1      2      0      2
    ABC        10 ABC        20      2      1      1      0
    ABC         2 ABC        20      2      1      1      0
    ABC         1 ABC        20      2      1      1      0
    ABC         9 ABC        20      2      1      1      0
    ABC         8 ABC        20      2      1      1      0
    ABC         7 ABC        20      2      1      1      0
    ABC         6 ABC        20      2      1      1      0
    ABC         5 ABC        20      2      1      1      0
    ABC         4 ABC        20      2      1      1      0
    ABC         3 ABC        20      2      1      1      0
    ABC        10 FOO        10      1      2      0      2
    ZZZ        10 FOO        10      1      2      0      2
    ZZZ        20 FOO        20      1      2      0      2Study this output to see how the different components work.
    For example, the first 12 rows of output show what we found when we were looking for ('ABC', 10). There were 12 rows in table x that had either ca='ABC' or c2=10 (or both). We used the rnk column to find the best match: lower numbers mean better matches. How did we do that? By using the DENSE_RANK function with a DESCending order by clause, that is, we used <tt> DENSE_RANK () OVER (... ORDER BY exp DESC) </tt>, which means that higher values of exp produce lower values from DENSE_RANK. What is exp? It's the column I called case_1_2. As you can see, when there was a perfect match ('ABC', 10), then case_1_2 had the value 3. Less perfect matches got lower values of case_1_2; for example ('ZZZ', 10) only had 2 in the case_1_2 column, and ('ABC', 5) only had 1. Why did case_1_2 have values of 3, 2 or 1 on those rows? Well, it's the sum of case_1 and case_2, so look at those individual columns, and see how they are computed.

  • Need help to write an interesting query

    I need some help in framing the query for the following scenario.
    I have three tables (in general)
    Departments
    DNO (PK)
    DNAME
    Employees
    DNO (FK to DNO in Departments)
    ENO (PK)
    CODE
    History
    seqid (PK)
    ENO (FK to ENO in Employees)
    The summary of the data in Employees table looks like below:
    DNo           No of employees
    10              10
    20               5
    30               8so there will be total of 23 records in employees table. I want to check if all the 10 employees from dept 10 are existing in history table and if exists I want to display the dno and dname from the employees and departments tables respectively. Even if the history table has 9 employees out of 10 from employees table I don't want the query to retrieve that dept details.
    Can any one help me with this?
    Meanwhile I will also try my level best and let you people know if I come up with anything.
    Thanks for your time

    Here the example that will help you.
    emp_test is the history table for you. You can change ct>9SQL> SELECT * FROM
      2  ( SELECT empno ,
      3          ename ,
      4       e.deptno,dname,
      5       COUNT(*) OVER(PARTITION BY e.deptno ORDER BY e.deptno) ct
      6     FROM EMP e ,DEPT d
      7     WHERE e.deptno=d.deptno
      8     AND EXISTS (SELECT 'x' FROM EMP_TEST T
      9                 WHERE T.empno=e.empno))
    10  WHERE ct>3;
         EMPNO ENAME          DEPTNO DNAME                  CT
          7499 ALLEN              30 SALES                   4
          7698 BLAKE              30 SALES                   4
          7654 MARTIN             30 SALES                   4
          7521 WARD               30 SALES                   4
    SQL> set linesize 300
    SQL> select * from emp_test;
         EMPNO ENAME                JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH                CLERK           7902 17-DEC-80      800.2                    20
          7499 ALLEN                SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD                 SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES                MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN               SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE                MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK                MANAGER         7839 09-JUN-81       2450                    10
    7 rows selected.
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80      800.2                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10formatted
    Message was edited by:
    devmiral

  • Need help with division within a query

    Hello all~
    I am trying to divide these two columns to get a % of case numbers involving an accident. Im pretty sure you need to use decode to avoid the divide by 0 error but not sure how to implement this within my query. When i run this query below, it gives me the result of "1", which is not correct. Can someone help me please?
    Oracle Version 10g
    ACCIDENT is a datatype VARCHAR
    CASE_NUMBER is a datatype VARCHAR
    select to_char(count(ACCIDENT),'999,999,999') as "ACCIDENT",
    to_char(COUNT(CASE_NUMBER),'999,999,999')as "CASE NUMBER",
    round(ratio_to_report(count(accident))
    OVER()*100,2)as "%"
    from      "PURSUIT"
    WHERE ACCIDENT = 'Y'
    AND
    (:P1_BEG_DATE IS NULL AND :P1_END_DATE IS NULL
    OR
    pursuit_date BETWEEN to_date(:p1_beg_date,'MM/DD/YYYY') and to_date
    (:p1_end_date,'MM/DD/YYYY'))
    AND(:P1_TROOP=pursuit.officer_troop OR :p1_troop IS NULL) 
    AND(:P1_RADIO=pursuit.officer_radio OR :p1_radio IS NULL)
    group by case_numberThanks
    Deanna

    Are you sure that the ANDs and ORs in your WHERE clause will take precedence properly?
    Also, if you always select only cases where there has been an accident, what percentage would you like to display? Surely in this case the percentage of cases involving in accident in cases where there was an accident.. is 100%?
    as a simpler example
    SELECT
      accident,
      ROUND(RATIO_TO_REPORT(count(*)) OVER() * 100)
    FROM
      pursuit
    GROUP BY
      accidentHere's a trick to neaten up those IS NULLs:
    SELECT
      accident,
      ROUND(RATIO_TO_REPORT(count(*)) OVER() * 100)
    FROM
      pursuit
    WHERE
      pursuit_date >= COALESCE(:p1_beg_date, pursuit_date) AND
      pursuit_date <= COALESCE(:p1_end_date, pursuit_date) AND
      officer_troop LIKE :p1_troop AND
      offcier_radio LIKE :p1_radio
    GROUP BY
      accidentTo wildcard a date, simply pass NULL in; the coalesce will replace the null with the pursuit_date from the record (thus the >= and <= becomes true)
    To wildcard the troop or the radio, simply pass a '%' symbol as the value of the parameter. If the front end code is already set up to pass nulls, use the COALESCE trick above

  • Need help to change BO generated query at universe leavel

    Hi
    Is there any possiblity to change sql at universe leavel.Kindly help me i am new to designer.
    The below is the BO generated query.
    SELECT specObjID 
    FROM SpecObj 
    WHERE SpecClass = dbo.fSpecClass('UNKNOWN') 
    Users are not intrested to go for coustomised sql in report leavel.
    I need to change the above sql accordingly due to some performance issues.
    The feilds that specify in the where clause SpecClass = dbo.fSpecClass('UNKNOWN')  move to from clause.
    Like below
    SELECT specObjID 
    FROM SpecObj ,SpecClass = dbo.fSpecClass('UNKNOWN') 
    WHERE 
    Kindly suggest me greatly appriciated.
    Thanks.
    Raj

    HI,
    As per your expectation query like below is not possible to give condition in from clause as per my understand,
    SELECT specObjID
    FROM SpecObj ,SpecClass = dbo.fSpecClass('UNKNOWN')
    WHERE
    I think your expected result can be achieved by giving condition while creating the object SpecObj.
    Steps:
    Go to universe, then edit the object SpecObj there you can give the where clause condition
    WHERE SpecClass = dbo.fSpecClass('UNKNOWN')
    This will increase your performance.
    Regrds,
    Ragoth.C

  • Need Help in tuning of the query

    Hi all,
    Can any body help me how we can rewrite this query in
    optimized way.
    SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
    FROM A,B
    WHERE A.C1 IN (
    SELECT COLUMN_1 FROM(
    (SELECT A.C1 AS COLUMN_1,
    COUNT(C1) AS COUNT,
    RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
    FROM A, B, C
    WHERE A.C1 = B.C3
    AND B.C2 = C.C1
    AND <other conditions>
    GROUP BY A.C1)
    WHERE RANK <= 10)
    AND A.C1 = B.C3
    AND <other conditions>
    ORDER BY A.C1
    I am using <other conditions> are same in outer query and inner query also.
    Thanks in Advance,

    Hi,
    Yes exactly I am looking TOP-10 results the query is like this
    SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
    FROM A,B
    WHERE B.C2 IN (
    SELECT COLUMN_1 FROM(
    (SELECT B.C2 AS COLUMN_1,
    COUNT(A.C1) AS COUNT,
    RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
    FROM A, B, C
    WHERE A.C1 = B.C3
    AND B.C2 = C.C1
    AND <other conditions>
    GROUP BY B.C2)
    WHERE RANK <= 10)
    AND A.C1 = B.C3
    AND <other conditions>
    ORDER BY B.C2
    Thanks

  • Help required in writing a query

    hi
    Consider a table (ShogenValue) with following data:
    Model_Id header_id Serial_no shogen_no si_val
    4329 1 40001 A0001 1
    4329 1 40001 B0001 2
    4329 1 50300 B0001 3
    4329 1 40001 C0001 4
    4329 1 50300 C0001 5
    4329 1 60001 C0001 6
    Select
         si_val
    From
         ShogenValue
    Where
    model_id = 4329
    And
         header_id = 1
    And
    serial_no = '60001'
    Is it possible to write a modified version of above query which will bring the following result:
    Model_Id header_id Serial_no shogen_no si_val
    4329 1 40001 A0001 1
    4329 1 50300 B0001 3
    4329 1 60001 C0001 6
    Meaning if a record exists for a particular shogen_no (Shogen_no C0001 has value corrosponding to '60001' in above query), pick it up, if it
    does not exist (Shogen_no B0001 does not have value corrosponding to '60001' in above case) then pick a record with one level less serial number ('50300' in above case) and so on.
    Thanx
    Regards
    Omer Imtiaz

    This should help, although it will probably not perform. Try it and see what the plan for it is.
    SELECT
    FROM
      shogenvalue sv,
      (SELECT
        max(serial_no) serial_no_max,
        shogen_no
      FROM
        shogenvalue
      WHERE
        model_id = 4329
        AND header_id = 1
        AND serial_no <= '60001'
      GROUP BY
        shogen_no
      ) svm
    WHERE
      sv.serial_no = svm.serial_no_max
      AND sv.shogen_no = svm.shogen_no
    ;HTH,
    Lennert

Maybe you are looking for