Select Query on BSEG

SELECT bukrs
         belnr
         gjahr
         augdt
         bschl
         koart
         umsks
         shkzg
         hkont
         kostl
         aufnr
         projk
         xref1
         wrbtr
         dmbtr
         ebeln
         ebelp
         lifnr
         sgtxt
    INTO TABLE t_bseg1
    FROM bseg FOR ALL ENTRIES IN payd
   WHERE bukrs EQ payd-zbukr
     AND belnr EQ payd-belnr
     AND gjahr EQ payd-gjahr
    AND koart IN ('K','S').
The above query does not bring me all the records for a particular BELNR.
However when i See in BSEG table through SE16 i found 4 records, but when i retrieve them through the above wuery it brings only three records.
ANy idea, what can i do to get the 4th record as well.. I checked the primary keys they are all same for all the 4 records in the DB table.
Regards

Hi Sam,
You were not fetching all the primary keys from the table and hence the problem comes.
Add BUZEI in the select query and try.
SELECT bukrs
belnr
gjahr
*BUZEI*
augdt
bschl
koart
umsks
shkzg
hkont
kostl
aufnr
projk
xref1
wrbtr
dmbtr
ebeln
ebelp
lifnr
sgtxt
INTO TABLE t_bseg1
FROM bseg FOR ALL ENTRIES IN payd
WHERE bukrs EQ payd-zbukr
AND belnr EQ payd-belnr
AND gjahr EQ payd-gjahr
AND koart IN ('K','S').
Hope this solves!!!
Regards.
Ganga

Similar Messages

  • ST05 Trace on a select query on BSEG table

    hi all,
    this is my select query on table BSEG table:
      SELECT bukrs
             belnr
             gjahr
             buzei
             KOART
             mwskz
             kostl
             lifnr
             aufnr
             werks
             ebeln
             txjcd
             projk FROM bseg
                   INTO TABLE i_bseg
                   FOR ALL ENTRIES IN i_ad_tab
                  WHERE bukrs EQ i_ad_tab-bukrs  AND
                        belnr EQ i_ad_tab-belnr  AND
                        gjahr EQ i_ad_tab-gjahr.
    when i m doing SQL trace ST05 on this query and in the detail statement showed the following query
    SELECT
      "MANDT" , "BUKRS" , "BELNR" , "GJAHR" , "PAGENO" , "TIMESTMP" ,
      "PAGELG" , "VARDATA"
    FROM
      "RFBLG"
    WHERE
      "MANDT" = ? AND  "BUKRS" = ? AND  "BELNR" = ? AND  "GJAHR" = ?
    ORDER BY
      "MANDT" , "BUKRS" , "BELNR" , "GJAHR" , "PAGENO"
    what is RFBLG table in SE11, but could not find it.
    what is RFBLG?also, the above select query giving me performance issues.. the "for all entries" clause is used as per norms...
    please suggest a solution..

    hi
    good
    The famous BSEG table is a cluster table.
    It is as was correctly stated part of the Accounting Document Segment. It is part of the Pool cluster RFBLG and lives in the package: FBAS (Financial accounting 'Basis').
    You can't read a cluster table exactly the way you read a database (old speak, transparent table).
    You can use a program to read called RFPPWF05
    Note 435694: Display BSEG item by calling FB09D (modified FB09)
    Other possiblity: Other possibility: CALL DIALOG 'RF_ZEILEN_ANZEIGE', but since this is a dialog I don't think this would work.
    In any event go to FBAS Package (development class) to see your business objects, class library and functions.
    you must use keyfields bukrs , belnr, gjahr
    (so 1st select table bkpf) to select bseg.
    or use secondary index tables:
    bsas, bsis, bsik, bsak, bsid, bsad
    Regards,
    Raj.

  • Poor performance due to select query

    Hey ppl,
    I am facing a problem in one of the select query on BSEG.
    The query is as given
    TYPES :BEGIN OF wa1_bseg,
            bukrs    TYPE bseg-bukrs,
            belnr     TYPE bseg-belnr,     
            gjahr         TYPE bseg-gjahr,
            buzei    TYPE bseg-buzei,
            fwbas    TYPE bseg-fwbas ,     
            pswbt    TYPE bseg-pswbt,
            hkont    TYPE bseg-hkont,
            wrbtr     TYPE bseg-wrbtr,
            ktosl     TYPE bseg-ktosl,
            koart     TYPE bseg-koart,
            shkzg    TYPE bseg-shkzg,
            mwskz   TYPE bseg-mwskz,
            qsskz    TYPE bsis-qsskz,
            dmbtr     TYPE bseg-dmbtr,
            flag        TYPE C,
            END OF wa1_bseg.
    DATA: it_bsegv TYPE TABLE OF wa1_bseg WITH HEADER LINE.
    SELECT bukrs belnr gjahr buzei fwbas pswbt hkont wrbtr  ktosl shkzg koart mwskz
    FROM bseg INTO TABLE it_bsegv
    FOR ALL ENTRIES IN it_ekko
       WHERE bukrs = 'MU51'     AND
                    gjahr IN s_fiscal    AND
                    valut IN s_budat1  AND
                    ebeln = it_ekko-ebeln.
    Even if there are only around 5 records in it_ekko it takes very long time in executing. Sumtimes it even shows 'time out' in
    foreground.   Kindly help me out with it

    Hi,
    Go through this link it will helpful,
    Re: Performance Issue with BKPF, BSEG, BSET
    Re: Reading BSEG: performance problems
    /people/rob.burbank/blog/2007/11/12/quickly-retrieving-fi-document-data-from-bseg
    Regards
    Adil
    Edited by: Syed  Abdul Adil on Jun 17, 2008 12:33 PM

  • Problem in SAP SET while firing select query

    Hi Experts,
    please check my code below
    DATA: BEGIN OF ibsis OCCURS 100, 
             ebeln LIKE bseg-ebeln,   
             ebelp LIKE bseg-ebelp,   
             bsis LIKE bsis,          
             ldgrp TYPE fagl_ldgrp.   
    DATA: END OF ibsis.              
    TYPES : BEGIN OF TY_ZFINITEMCAT,
                   pstyv TYPE vbap-pstyv,
                 END OF TY_ZFINITEMCAT.
    DATA : GT_ZFINITEMCAT TYPE STANDARD TABLE OF TY_ZFINITEMCAT.
    FIELD-SYMBOLS : <fs_ZFINITEMCAT> TYPE TY_ZFINITEMCAT.
    DATA: l_item_catecory TYPE pstyv.
    SELECT VALFROM
              INTO TABLE GT_ZFINITEMCAT
              FROM SETLEAF
              WHERE SETNAME EQ 'ZFIN_ITEMCAT'.
    LOOP AT ct_ibsis[] ASSIGNING <ibsis>.
    "Check if we can find one item of the wrong category, if so then we remove the documents.
         SELECT SINGLE pstyv INTO l_item_catecory
           FROM vbap
           WHERE vbeln = <ibsis>-bsis-zuonr
             AND pstyv NOT IN GT_ZFINITEMCAT.  "getting error here (The line structure of the table "GT_ZFINITEMCAT" is incorrect.)
         IF sy-subrc = 0.
           DELETE ct_ibsis[] WHERE bsis-zuonr = <ibsis>-bsis-zuonr.
         ENDIF.
       ENDLOOP.
    fetching data from SET(GS01) but while activating i am getting error in another select query(The line structure of the table "GT_ZFINITEMCAT" is incorrect.),
    please provide your valuable suggestion.
    Regards,
    Subhanshu Shrivastava

    When using IN you must use a range table afterwards.
    Try this :
    DATA: BEGIN OF ibsis OCCURS 100,
             ebeln LIKE bseg-ebeln,  
             ebelp LIKE bseg-ebelp,  
             bsis LIKE bsis,         
             ldgrp TYPE fagl_ldgrp.  
    DATA: END OF ibsis.             
    DATA: gt_zfinitemcat type range of vbap-pstyv,
    FIELD-SYMBOLS : <fs_ZFINITEMCAT&gt; TYPE any.
    DATA: l_item_catecory TYPE pstyv.
    SELECT VALFROM AS LOW
              INTO CORRESPONDING FIELDS OF TABLE GT_ZFINITEMCAT
              FROM SETLEAF
              WHERE SETNAME EQ 'ZFIN_ITEMCAT'.
    LOOP AT GT_ZFINITEMCAT ASSIGNING <fs_ZFINITEMCAT>.
         <fs_ZFINITEMCAT>-SIGN       = 'I'.
         <fs_ZFINITEMCAT>-OPTION = 'EQ'.
    ENDLOOP.
    LOOP AT ct_ibsis[] ASSIGNING <ibsis&gt;.
    "Check if we can find one item of the wrong category, if so then we remove the documents.
         SELECT SINGLE pstyv INTO l_item_catecory
           FROM vbap
           WHERE vbeln = <ibsis&gt;-bsis-zuonr
             AND pstyv NOT IN GT_ZFINITEMCAT.  "getting error here (The line structure of the table "GT_ZFINITEMCAT" is incorrect.)
         IF sy-subrc = 0.
           DELETE ct_ibsis[] WHERE bsis-zuonr = <ibsis&gt;-bsis-zuonr.
         ENDIF.
       ENDLOOP.

  • Select query in driver program for sapscript

    Hi All,
    I want to select buzei, zuonr,sgtxt,meins from bseg ,temp (a temporary variable of type p deciamls 2), tmp (another temporary variable) and dmbtr from HBSEG (a structure of type bseg) . under the cond
    koart ne 's' or
    xauto ne 'x' or
    buzid ne 't'.
    I have to write this select query usinf a WORKAREA . After this select query i give WRITE_FORM as i call there vairables in script.Its very urgent.
    thanks much

    Hi,
    You can use inner join. Consider this simple example.
    data : a type zvijirank occurs 10 with header line,
              b type zvijirank1 occurs 10 with header line.
    data : name like zvijirank-name,
           total like zvijirank1-total,
           reg_no like zvijirank.
    *       regno type i.
    data : begin of wa,
           name type zvijirank-name,
           total type zvijirank1-total,
           branch type zvijirank1-branch,
           reg_no type zvijirank-reg_no,
    *       FNAME TYPE ZVIJIRANK2-F_NAME,
    *       MNAME TYPE ZVIJIRANK2-M_NAME,
    *       CITY TYPE ZVIJIRANK2-CITY,
    *       TEL_NO TYPE ZVIJIRANK2-TEL_NO,
           end of wa.
    data : it like standard table of wa with header line,
             it1 like standard table of wa with header line.
    call selection-screen 9010.
    select a~name b~total b~branch a~reg_no into table it from zvijirank as a inner join zvijirank1 as b on a~reg_no = b~reg_no .
    loop at it.
    if it-reg_no eq regno.
    write : 'NAME   :', it-name,
            'REG_NO :', it-reg_no,
             'TOTAL :', it-total.
    ENDIF.
    endloop.
    Thanks,
    Reward If Helpful.

  • Can we use concatenate in where clause of a select query

    I have a select query as follows....
        SELECT ebeln ebelp belnr vgabe bwart DMBTR
                                 FROM ekbe
                                 INTO TABLE i_ekbe
                                 FOR ALL ENTRIES IN i_blck
                                 WHERE ebeln =  i_blck-ebeln AND ebelp =                                                                               
    i_blck-ebelp.
    Now i want to retrieve data from BKPF ..can i write a select query something like....
    select * from BKPF into itab
                FOR ALL ENTRIES IN i_ekbe
                where awkey = ( conatenate i_ekbe-belnr i_ekbe-gjahr )
    OR ELSE...is there any other way to link table ekbe and bseg ???

    Hi Poonam,
    SELECT ebeln ebelp belnr vgabe bwart DMBTR
    FROM ekbe
    INTO TABLE i_ekbe
    FOR ALL ENTRIES IN i_blck
    WHERE ebeln = i_blck-ebeln
    AND ebelp = i_blck-ebelp.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where belnr = i_ekbe-belnr.
    If u want to check with AWKEY concatenate into seperate field and then use to check in where condition.
    data: lw_awkey(20) type c.
    CONCATENATE  i_ekbe-belnr  i_ekbe-gjahr  INTO lw_awkey.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where awkey = lw_awkey
    Best regards,
    raam

  • Performance problem with selecting records from BSEG and KONV

    Hi,
    I am having performance problem while  selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
    Regards,
    Prashant

    Hi,
    Some steps to improve performance
    SOME STEPS USED TO IMPROVE UR PERFORMANCE:
    1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
    2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
    3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
    4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
    5. Avoid using nested SELECT statement SELECT within LOOPs.
    6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
    7. Avoid using SELECT * and Select only the required fields from the table.
    8. Avoid nested loops when working with large internal tables.
    9. Use assign instead of into in LOOPs for table types with large work areas
    10. When in doubt call transaction SE30 and use the examples and check your code
    11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
    12. Use "CHECK" instead of IF/ENDIF whenever possible.
    13. Use "CASE" instead of IF/ENDIF whenever possible.
    14. Use "MOVE" with individual variable/field moves instead of "MOVE-
    CORRESPONDING" creates more coding but is more effcient.

  • BDC select query with addition based on all If conditions

    Hi can any one send me the select query with conditions like
    If Itab is not initial.
    Endif. and if possible with valiadations messages also.
    IF CHECK_NUMBER of CHECK_ADVICE of the flat file = PAYR-CHECT. Then update SAP field BSEG-XREF2 .
    9.     When Flat file check Number = PAYR-CHECT then Insert or Update Flat file RECEIPT_DATE into SAP field BSEG-XREF1.
    Please send me immediately.

    >     SELECT rsnum
    >            rspos
    >            matnr
    >            werks
    >         lgort
    >            shkzg
    >            aufnr
    >            bdmng
    >            enmng                      
    >            FROM  resb INTO  TABLE it_rsnum FOR ALL ENTRIES IN it_aufnr
    >            WHERE rsnum EQ it_aufnr-rsnum
    >            AND   xloek NE 'X'
    >            AND   postp NE 'X'
    >            AND   resbbdmng GE resbenmng.
    >   ENDIF.
    >
    > Database Table RESB: 40,000,000 Records (40 Million)
    > Internal Table   it_aufnr:  20,000 Entries
    > Entries selected from RESB: 150,000.
    >
    Hi,
    the problem is the big for all entries table.
    Your 20.000 records FAE will be split into SEVERAL sql statements depending on the size of the table.
    Where do you get the it_auftrn from?
    If it's another transparent table try to JOIN this table to your big table.
    SELECT rsnum
                rspos
                matnr
                werks
            lgort
                shkzg
                aufnr
                bdmng
                enmng                      
                FROM  resb JOIN tab_auftrn  on  resbrsnum = tab_auftrnauftrn
                AND   xloek NE 'X'
                AND   postp NE 'X'
                AND   resbbdmng GE resbenmng.
    Make sure that your WHERE filter and the JOIN keys on both tables are supported by indexes.
    150.000 records about of 40 Mio. can definitly be serviced by an appropriate index:
    i.e. Index fields (check your PK or secondary indexes):
    rsnum
    enmng                      
    aufnr
    bye
    yk

  • Select query is not executing

    Hi Friends,
    my code is :
    itab-vbeln = bseg-vbeln.
    if not itab-vbeln is initial.
    select single vbeln inco1 inco2 into ( itab-vbeln itab-inco1 itab-inco2)
    from vbrk where vbeln = itab-vbeln.
    appned itab.
    note : here inco1 inco2 are incoterms
    my question is  can we direct move the values of bseg-vbeln into itab-vbeln. ???
    and i am generating the report with one varient , when i debug this report the
    there is no value in bseg-vbeln. it is showing null value.thats why my select query is not working..but i want execute this select query final.
    in output i want display the inco1 inco2 data.(incoterms)
    any help please.
    urgent.
    regards,
    vijay.

    Hi Vijay,
    First you need to check it out whether <b>itab-vbeln = bseg-vbeln</b> is in with in LOOP or not (<b>if ITAB is intenal table</b>)
    if itab is internal table you should write above statement with in loop, and also check it out in debug mode why bseg-vbeln value is not coming.
    and one more thing you need to make small correction in ur code use ',' .
    select single vbeln inco1 inco2 into ( <b>itab-vbeln, itab-inco1, itab-inco2</b>)
    from vbrk where vbeln = itab-vbeln
    Note: when ever use select single u should pass values into work area, dont use internal table .
    <b>if you have more doubts just send your entire code then i will rewrite it.</b>
    <b>Reward with points if useful.</b>
    Regards,
    Vijay Krishna

  • Issue with one Select Query in  PBS Archive Translation Tool

    Hi All,
    Iam having X mark symbol against the select query from EKET table
    This is the select query in my actual program and when i convert this using PBS Archive Translation Tool i have a X mark against this select query
    SELECT SINGLE BANFN FROM EKET INTO V_BANFN WHERE EBELN = BSEG-EBELN AND
                                                      EBELP = BSEG-EBELP AND
                                                      ETENR = '0001'.
    I guess i have to modify this select query because EKET table has transaction data and we cannot ignore this X mark.
    Let me know if iam wrong
    ALso , iam confused whether a select query with X needs to fixed or can be ignored
    Thanks

    Hi ,
    Any Suggestions
    Thanks

  • Select query not working

    Hello Experts,
    i am using select query like
    SELECT SHKZG SUM( DMBTR ) AS DMBTR
      FROM BSIK INTO CORRESPONDING FIELDS OF TABLE ITAB_BSIK
      WHERE BUKRS = W_BUKRS
      AND LIFNR = WA_BSEG-LIFNR
      AND ( BLDAT BETWEEN W_DATe_low AND W_DATe_high )
      GROUP BY SHKZG.
    I checked with table by giving the values same as here.
    In table m getting data , but dont know y after executing this query m not getting results.
    value of sy-subrc equals to 4.
    Can any body tel me what might be the problem??
    Thanks & Regards,
    Manisha
    Edited by: Rob Burbank on Aug 3, 2010 11:12 AM

    Hello ,
    SUM and AVG commands runs on your database system and calculations with type floating numbers.
    It can cause a low performance and sometimes wrong results.
    In your example ,
    if you are using Packed numbers in your internal table for DMBTR ( like bseg-dmbtr )
    and sum of the related records does not fit into this fields than select can not run.
    I can recommend u this code :
    DATA :
    begin of w_bsik,
      shkzg LIKE bsik-shkzg,
      dmbtr LIKE bsik-dmbtr,
    END OF w_bsik,
    t_bsik LIKE STANDARD TABLE OF w_bsik.
    SELECT shkzg dmbtr FROM bsik INTO w_bsik
    WHERE ...
       COLLECT w_bsik INTO t_bsik.  <--- Collect command does sum operation based on SHKZG
    ENDSELECT.
    I hope it helps.

  • SELECT query performance issue

    Hello experts!!!
    I am facing the performance issue in the below SELECT query. Its taking long time to execute this query.
    Please suggest how can i improve the performance of this query.
    SELECT MBLNR MATNR LIFNR MENGE WERKS BUKRS LGORT BWART INTO CORRESPONDING FIELDS OF TABLE IT_MSEG
        FROM MSEG
        WHERE MATNR IN S_MATNR
        AND LIFNR IN S_LIFNR
        AND WERKS IN S_WERKS
        AND BUKRS IN S_BUKRS
       AND XAUTO = ''
        AND BWART IN ('541' , '542' , '543' , '544', '105' , '106').
    Thanks in advance.
    Regards
    Ankur

    Hi Ankur,
    the MSEG index for material is
    Index MSEG~M
    MANDT
    MATNR
    WERKS
    LGORT
    BWART
    SOBKZ
    It could be used very efficient if you supply values for MATNR, WERKS and LGORT.
    There is no index on LIFNR. IKf you want the data for specific vendor(s), you should select from EKKO first, ir has index Index EKKO~1
    MANDT
    LIFNR
    EKORG
    EKGRP
    BEDAT
    You can JOIN EKKO and EKBE to get the BSEG key fields GJAHR BELNR BUZEI directly.
    I don't know your details but I think you can get all you need from EKKO and EKBE. You may also consider EKPO as is has a material index Index EKPO~1
    MANDT
    MATNR
    WERKS
    BSTYP
    LOEKZ
    ELIKZ
    MATKL
    Do you really need the (much bigger) MSEG?
    Regards,
    Clemens

  • Select Query Problem

    Hi Experts,
    I am having a select query in which I am using a variable in the where condition but it is giving error. Please suggest how to use variable in the select query.
    The query I am using is a s below.
    select * from zexc_rec into table it_ZEXC_REC
          where
           LIFNR in S_LIFNR and
          DOCNO in S_DOCNO and
          DOCTYP in doc_typ and
          DATE1 in S_DATE1 and
          MATNR in S_MATNR.
    Here doc_typ is a variable.
    Thanks.

    Rahul,
    use RANGES type variable instead of variable . It acts as a select-options variable. Thn use this variable in SELECT query with IN.
    Eg :
    RANGES r_t510 FOR t510-lgart.
        r_t510-low = '1600'. 
        APPEND r_t510.
        r_t510-low = '3190'. 
        APPEND r_t510.
    Note  : can be use SIGN, OPTIONS properties too in RANGES type.
    More deatils go through on HELP of RANGES
    Rgds,
    Ranjith

  • Oracle 11g :SELECT query blocked..??

    Hi Experts,
    could you please explain why the below SQL query is blocked?
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=469 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=367 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    I am scratching my head without any solution when I had a look at the db today. Thanks in advance for your help.
    Regards,
    Boris
    Edited by: user12075620 on Dec 4, 2012 8:58 AM

    The SELECT statement is not blocking the UPDATE. As I said in the previous reply, the string that this query produces does not match the logic.
    This query is (at least on the surface) correctly identifying that session 1 is blocking session 2. Session 1 holds some lock that session 2 is waiting on. So far, so good. Since session 2 is waiting on the lock, we can easily enough see what session 2 is running (the UPDATE statement). But since session 1 is not blocked, it is potentially off running a ton of other SQL statements (or no SQL statement at all). The query is looking to see what session 1 is running currently. It has no way of determining what session 1 ran at some point in the past to acquire the lock in the first place.
    Going back to my KING example,
    At noon, session 1 runs
    UPDATE emp
       SET sal = sal * 2
    WHERE ename = 'KING'Session 1 now has a lock on the KING row in the EMP table. But session 1 neither commits nor rolls back, it is still in a transaction. Session 1 might not have any more activity for a long time-- the user might go off to lunch, for example (obviously, applications should not be designed to allow users to maintain open transactions indefinitely, but not all applications are designed correctly). Or it might start running other queries. Let's say that session 1 now runs a query that is going to go for an hour
    SELECT *
      FROM giant_view_with_lots_of_computationsNow, at 12:45, session 2 comes in and runs
    UPDATE emp
       SET bonus = 100
    WHERE ename = 'KING'Session 2 is blocked. Session 2 is running the UPDATE statement. Session 1 still holds the lock but it is running some completely unrelated SQL statement.
    If we run the query you posted, the query will correctly report that session 1 is running the query against the GIANT_VIEW_WITH_LOTS_OF_COMPUTATIONS but incorrectly imply that this SELECT query is the source of the lock. It is not. It simply happens to be the query that the session that does hold the lock happens to be executing at the current moment (why the application seems to be running a lot of queries that select a constant from dual is a separate question).
    Justin

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

Maybe you are looking for