Regarding BP Balance Query.

Hello Experts,
I need query for BP Balance
BP Group Name,  BP Code,  BP Name,  Sales Employee Name,  BP Balance1 (01-04-2009 To 31-03-2010),
BP Balance2 (01-04-2010 To 31-03-2011),  BP Balance3 (01-04-2011 To 31-03-2012)
Thanx in advance.
Help for this query.
Regards
Pratik

Hi
try this
DECLARE @ENDDATE
DATETIME SET @ENDDATE = (SELECT MAX(T2.DOCDATE) FROM [DBO].[INV1] T2 WHERE T2.DOCDATE <= '[%0]')
SELECT T0.[CardCode]
,  T0.[CardName]
, t4.groupname
, T3.SLPNAME
, DBO.F_Ypoloipo_Hmer_basilis(T0.cardcode,@ENDDATE)
FROM OCRD T0
INNER JOIN OCTG T1 ON T0.GroupNum = T1.GroupNum
INNER JOIN OINV T2 ON T0.CARDCODE=T2.CARDCODE
INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
inner join ocrg t4 on t4.groupcode=t0.groupcode
WHERE T2.Docdate <= @ENDDATE
scalar valued function
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION [dbo].[F_Ypoloipo_Hmer_basilis]
(@cardcode AS NVARCHAR(10),
@ENDDATE AS DATETIME
RETURNS
NUMERIC(19,2)
AS
BEGIN
DECLARE
@RESULT1 AS NUMERIC(19,2),
@RESULT2 AS NUMERIC(19,2),
@RESULT AS NUMERIC(19,2)
SELECT @RESULT1=SUM(T0.debit)
FROM jdt1 T0
--WHERE T0.SHORTNAME=@CARDCODE AND (T0.dueDATE <= @ENDDATE)
WHERE T0.SHORTNAME=@CARDCODE AND (T0.refDATE <= @ENDDATE)
SELECT @RESULT2=SUM(T0.credit)
FROM jdt1 T0
--WHERE T0.SHORTNAME=@CARDCODE AND (T0.dueDATE <= @ENDDATE)
WHERE T0.SHORTNAME=@CARDCODE AND (T0.refDATE <= @ENDDATE)
SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
RETURN @RESULT
END

Similar Messages

  • GL Account Balance Query Issue

    Hi,
      I'm trying to extract GL Balances in the following format
    Company Segment(Segment2)  ||   Account Number(Segment1) ||  Cost Center Segment4 ||  Account Descr ||  Actual Flag || Account Type || Activity || Activity in Period || Currency || Period End date || Account Balance
    Here's my query :
    SELECT     gcc.segment4  "Company Segment",
               gcc.segment1  "Account",
               gcc.segment2  "Cost Center",
               a1.description "Account Description",
             --  a2.description Company_Description,
               Decode(gcc.account_type,'A','Asset','E','Expense','L','Liability','O','Equity','R','Revenue') "Account Type",
               Decode(gcc.enabled_flag,'Y','TRUE','FALSE')  "Active Account",
               Decode(abs(bal.Period_net_dr - bal.Period_net_cr),0,'FALSE','TRUE') "Activity in Period",
               bal.actual_flag  " Actual Flag",
               bal.currency_code  "Account Currency",
               per.end_date  "Period End Date",
               SUM(( NVL(bal.PERIOD_NET_DR,0) + NVL(bal.BEGIN_BALANCE_DR,0))) - SUM(NVL(bal.PERIOD_NET_CR,0)+NVL(bal.BEGIN_BALANCE_CR,0)) -
                         SUM( NVL(bal.BEGIN_BALANCE_DR,0) - NVL(bal.BEGIN_BALANCE_CR,0))   "Account Balance"
    FROM        apps.fnd_flex_values_vl a1,      --- For Account Segment
                apps.fnd_flex_values_vl a2,              -- For Cost Center
                apps.gl_code_combinations gcc,
                apps.gl_balances bal,
                apps.gl_periods per
    WHERE       a1.flex_value = gcc.segment1 
    AND         a2.flex_value = gcc.segment2
    and         a1.flex_value_set_id = 111111        -- Value set id for Account
    ---and         a2.flex_value_set_id = 222222    -- Value set id for Cost Center
    and         gcc.code_combination_id = bal.code_combination_id
    and          bal.period_name = per.period_name
    and         gcc.segment1 in ('777777')      --- Sample Account for testing only
    --and         gcc.segment2 in (222222)
    and         per.period_set_name ='GL_CALENDAR'
    and         bal.period_name ='SEP-13'
    and         bal.actual_flag='A'
    group by    gcc.segment4,
                gcc.segment1,
                gcc.segment2,
                a1.description,
               --            Decode(gcc.account_type,'A','Asset','E','Expense','L','Liability','O','Equity','R','Revenue'),
                Decode(gcc.enabled_flag,'Y','TRUE','FALSE'),
                Decode(abs(bal.Period_net_dr - bal.Period_net_cr),0,'FALSE','TRUE'),
                bal.actual_flag,
                bal.currency_code,
                per.end_date
                order by gcc.segment1,gcc.segment2
    1) If I  comment value set id 222222(Cost Center), then I'm getting 15 Records ,If I uncomment that I'm getting 10 records?Is there anything wrong with my queryAs I'm not displaying descriptions for cost center and company do I need to join fnd_flex_values_vl again or not ? 2) To check activity in particular period in this case for SEP-13,I'm using the following clause : Decode(abs(bal.Period_net_dr - bal.Period_net_cr),0,'FALSE','TRUE') Do I need to check ABS values also ro not?

    Hi,
      You can do this with WD dynamic programming.
      You can do with domodifyview badi for accounting component /SAPSRM/WDC_UI_DO_ACC.
      You need to handle both views 'V_DO_ACCOUNTING' and  'V_DO_ACCOUNT_DETAIL' in the domodifyview badi implementation.
    I am sending the sample  code. How to attach the custom search help dynamically.
      DATA lo_nd_comp_context    TYPE REF TO if_wd_context_node.
      DATA lo_nd_acc_context     TYPE REF TO if_wd_context_node.
      DATA lo_nd_info_acc        TYPE REF TO if_wd_context_node_info.
      DATA lv_value_help_mode    TYPE i.
      DATA lv_value_help         TYPE string.
      " Read Context
      lo_nd_comp_context = wd_context->get_child_node( name = 'COMP_CONTEXT' ).
      " get node info object of accounting node
      IF lo_nd_acc_context IS BOUND.
        lo_nd_info_acc = lo_nd_acc_context->get_node_info( ).
      ENDIF.
      " continue only if node info is supplied
      IF lo_nd_info_acc IS BOUND.
        " get current search help info
        lo_nd_info_acc->get_attribute_value_help(
          EXPORTING
            name            = 'G_L_ACCT'
          IMPORTING
            value_help_mode = lv_value_help_mode
            value_help      = lv_value_help
    " Below this will add the custom search help from SRM .
             lo_nd_info_acc->set_attribute_value_help(
            EXPORTING
              name            = 'G_L_ACCT'
              value_help_mode = 'BUS2121'
              value_help      = 'Z_F4-Your search help'   " you own search help.
      endif.
    Regards,
    Devi prasad

  • Balance query

    Hi,
    i am using the below query to get the balance for a particular date.
    select a1.stmt_date,i1.field_8,m1.field_9,(sum(a1.qty_receipt)-sum(a1.qty_delivery))
    from t1 i1,t2 m1,t3 a1
    where
    i1.acc_no=m1.acc_no and
    i1.acc_no=a1.acc_no and
    i1.acc_no=100006850
    group by a1.stmt_date,i1.field_8,m1.field_9
    order by 1,2,3
    output is
    STMT_DATE     FIELD_8     field_9     (SUM(A1.QTY_RECEIPT)-SUM(A1.QTY_DELIVERY))
    4/15/08 12:00 AM     4111986     340857     100000
    4/15/08 12:00 AM     4431455     340857     8325000
    4/16/08 12:00 AM     4111986     340857     100000
    4/16/08 12:00 AM     4431455     340857     13325000
    but my problem is i want balance based on field_8 not based on stmt_date field.
    also i need that to be displayed in select statement.
    can any one help me regarding this.

    SQL> with samp_table as (
      2  select '4/15/08 12:00 AM' a, '4111986' b, '340857' c, '100000' d from dual
      3  union all
      4  select '4/16/08 12:00 AM' A, '4111986'  B, '340857' C, '100000' D from dual union all
      5  select '4/15/08 12:00 AM' a, '4431455' b, '340857' c, '8325000' d from dual union all
      7    8  select '4/16/08 12:00 AM' A, '4431455' B, '340857' C, '13325000' D from dual
      9  )
    10  select distinct t1.a, t1.b, t1.c, t2.sumcol from samp_table t1,  (select b, sum(d) sumcol from samp_table group by b) t2
    where t1.b=t2.b
    order by 4;
    A                B       C          SUMCOL
    4/15/08 12:00 AM 4111986 340857     200000
    4/16/08 12:00 AM 4111986 340857     200000
    4/15/08 12:00 AM 4431455 340857   21650000
    4/16/08 12:00 AM 4431455 340857   21650000

  • Amount to Reconcile in Debtors Outstanding  balance query

    Hi Experts.
    Below is the query i used to run Debtors Outstanding Balance. and its working fine but we need Amount To Reconcile Debit and Amount To Reconcile Credit Fields also..
    so pls modify this query and help me...
    SELECT T0.[TransId],T0.[RefDate], T0.[TransType] AS 'Origin Doc.Type', T1.[BaseRef] AS 'Origin Doc.No', T1.[ShortName], T2.[CardName],
    T1.[Account], T1.[ContraAct], T1.[CreatedBy], T1.[Debit], T1.[Credit], T1.[BalDueDeb], T1.[BalDueCred], T1.[LineMemo]
    FROM dbo.OJDT T0 
    INNER JOIN dbo.JDT1 T1 ON T0.TransId = T1.TransId
    INNER JOIN dbo.OCRD T2 on T2.CardCode = T1.[ShortName]
    WHERE T1.[MthDate] IS NULL AND T2.[CardName] LIKE '[%0]%'
    Regards,
    Vamsi

    Do you mean this:
    SELECT T0.[TransId],T0.[RefDate], T0.[TransType] AS 'Origin Doc.Type', T1.[BaseRef] AS 'Origin Doc.No', T1.[ShortName], T2.[CardName],
    T1.[Account], T1.[ContraAct], T1.[CreatedBy], T1.[Debit], T1.[Credit], T1.[BalDueDeb], T1.[BalDueCred], T1.[LineMemo], (T1.[Debit] - T1.[BalDueDeb]) AS 'Amount To Reconcile Debit', (T1.[Credit]-T1.[BalDueCred]) AS 'Amount To Reconcile Credit'
    FROM dbo.OJDT T0 
    INNER JOIN dbo.JDT1 T1 ON T0.TransId = T1.TransId
    INNER JOIN dbo.OCRD T2 on T2.CardCode = T1.[ShortName]
    WHERE T1.[MthDate] IS NULL AND T2.[CardName] LIKE '[%0]%'
    Thanks,
    Gordon

  • BEx Load Balancing Query

    Hi,
    We are at Bi 7.00/AIX/Oracle.
    How can we load balance the query running via BEx. Most of the time it is going to CI, which is message server and not part of logon group. Our Web Queries are running fine because we have put a Logon Group in SICF for a required service.
    How can I resolve the BEx issue.
    Please let me know if it is possible.
    Thank you.
    Sume

    If you log on to BEx Analyzer and connect to a system you select an entry from the SAP Logon pad just as if you connect to a system with SAP GUI. In the system entry in the SAP Logon pad you can specify a logon group. This logon group is then also used in BEx Analyzer. Probably your system points to the CI without logon group.
    Regards, Klaus

  • Regarding Vendor balance confirmation Report

    Hi Experts
           I have a small issue in FI Module while using standard Programe(SAPF130K).
    If you execute the above program and pass the parameters vendor no and posting date then only get the data.
    But my client requirment is Get the data based on ProfitCenter(PRCTR) and they want only Open Items.
    In standard program used  BSIK and BSAK.
    These two tables Profit Center data is not available.How can i get data based on Profit Center.
    My variant
    Select-Options is
    given below.
    "--Select Options"
    Vendor  1010000001
    CompanyCode 1000
    Reconciliation Key Date   --  current date
    Futhter Selections Check Individual Vendors
    Total Balance
      Check zero Balances
    Keydate For Master Records
    Form Set
            selected for Empty One in F4Help
    Sort Var.for Correspondence       K3
    Line item sorting                 P3
    Date of issue                current date  
    Check No Reply(because not assaigned to Company Code)
    Printer for Form Set           LP01
    Printer for Reconcil. List     LP01
    Printer for results table      LP01
    Printer for selections         LP01
    Regards
    Hari

    HI,
    Kindly use table FAGLFLEXA and FAGLFLEXT for getting profit center data .Assign points if useful.
    Regards,
    Shradha.

  • Regarding Vendor Balance Confirmation Report(FI Module Issue)

    Hi Experts
    I have a small issue in FI Module while using standard Programe(SAPF130K).
    If you execute the above program and pass the parameters vendor no and posting date then only get the data.
    But my client requirment is Get the data based on ProfitCenter(PRCTR) and they want only Open Items.In Select-Options Profit Center is not there.I need to add PRCTR(Profit Center) in select-options.
    In standard program used BSIK and BSAK.
    These two tables in Profit Center data is not available.How can i get data based on Profit Center.
    My variant
    Select-Options is
    given below.
    "--Select Options"
    Vendor 1010000001
    CompanyCode 1000
    Reconciliation Key Date -- current date
    adding this select-option---Profit Center  10200120
    Futhter Selections Check Individual Vendors
    Total Balance
    Check zero Balances
    Keydate For Master Records
    Form Set
    selected for Empty One in F4Help
    Sort Var.for Correspondence K3
    Line item sorting P3
    Date of issue current date
    Check No Reply(because not assaigned to Company Code)
    Printer for Form Set LP01
    Printer for Reconcil. List LP01
    Printer for results table LP01
    Printer for selections LP01
    Regards
    Hari

    HI,
    Kindly use table FAGLFLEXA and FAGLFLEXT for getting profit center data .Assign points if useful.
    Regards,
    Shradha.

  • REGARDING OPENING BALANCE AND CLOSING BALANCE

    Hi, All
    After executing the TCode - FBL3N, we get the details list. There we also need to display the OPENING BALANCE AND CLOSING BALANCE according to G/L Account and Company Code.

    Hi
    For opening balance, please use transaction F.01.
    Then go to special evaluations and choose balance sheet type 4 (opening balance)
    Kind regards
    JeVe

  • Regarding Opening balances of GL Account as on date

    hi
    can any body give the tables name  or  FM or Bapi
    for  GLaccount opening balances as on  date or  priod.
    Regards
    Spandana

    hi
    thanks  supriya
    Spandana

  • AP Subledger Trial Balance query in R12

    I have to display below columns in the output(AP Subledger Trial Balance) in R12:
    GL_CODE_COMBINATIONS(Segment1,segment3,segment4)
    GL_PERIODS(END_DATE)
    XLA_TRIAL_BALANCES(remaining amount)
    I have written a sql query but i need to satisfy below conditions in the below query. I am facing issues with the joins.can any one please help me to solve issue.
      ‘Accounting Period’ parameter needs to be added in the below query.
    The sql query will generate the AP subledger balance data for the particular operating unit from where the report is run.
    The report will give ‘at point in time’ data for the entire period for which the extract is run.
    Example:
    When the report is run on 01-Jul-2014 for the period ‘JUL-14′, then the report will extract all the data for JUL-14 at that point in time , i.e. the sysdate would be considered
    SELECT gcc.segment1,
    gcc.segment3,
    gcc.segment4,
    tb1.diff remaining_amount,
    glp.end_date –join condition required
    FROM gl_code_combinations gcc,
    gl_periods glp,
    (SELECT tb.code_combination_id,tb.ledger_id,
    SUM (NVL (tb.acctd_rounded_cr, 0)),
    SUM (NVL (tb.acctd_rounded_dr, 0)),
    SUM (NVL (tb.acctd_rounded_cr, 0))
    – SUM (NVL (tb.acctd_rounded_dr, 0)) diff,
    tb.gl_date
    FROM xla_trial_balances tb
    WHERE tb.definition_code IN(‘XX_US’,’XX_CA’)
    AND TRUNC(tb.gl_date) <= TRUNC(SYSDATE) –TO_DATE ('1-JUN-2014')
    GROUP BY tb.code_combination_id,
    tb.gl_date,tb.ledger_id
    HAVING SUM (NVL (tb.acctd_rounded_cr, 0))
    SUM (NVL (tb.acctd_rounded_dr, 0))) tb1
    WHERE tb1.code_combination_id = gcc.code_combination_id
    –Join condition required for gl_periods table to display end_date column.
    –org_id and period_name parameters are required

    Hi Vamsi,
    I've recreated the standard oracle Trial balance package & XML file . Now i'm able to populate the data into custom table as well as standard table . But the report out doesn't show data in it . it just shows report title, columns bUT NO DATA. the xml file itself doesnt contain data. The custom report completes in 2 mins. But standard report completes in 7 mins
    Steps
    1. Create custom package similar to oracle standard package & added new insert statement to populate trial balance data into custom table.
    2. created new datadefinition with new datatemplate(refering custom package) similar to oracle standard datatemplate.
    3. create template same as standard template.
    4. copy of standard conc program with custom application
    5. Ran the report ...able to populate data into custom table .....but unable to see data in the report.
    Please let me know if i'm missing anythng.

  • AP Trial Balance Query.

    I'm trying to re-create the AP Trial Balance report so I can add additional info for the Accountants allowing them to analyze the data better.
    we are in R12.1.3
    Can any anyone provide query that gives the same data as 'Accounts Payable Trial Balance'.
    Please in urgent need....
    Gurus help me out...
    Thanks,
    Raj.

    Hi,
    Were u able to create customized version of AP trial balance report. Please provide somepointers if so.
    Thanks
    TR

  • Regarding opening balance of vendor

    we have a vendor which total balance on the date 03.11.2011 is Rs.15000000. But what is the requirement is now with the same vendor we should have opening balance on dated 01.04.2011 is Rs.100000. is this possible?(to put this amount as opening balance for this fiscal yr.
    Regards
    Abhisekh

    Hi,
    You can check the balance of the vendor, according to the period wise...
    FYI
    Please check with below T-Codes:
    S_ALR_87012077 - Vendor Information System
    S_ALR_87012082 - Vendor Balances in Local Currency
    S_ALR_87012093 - Vendor Business
    S_ALR_87012079 - Transaction Figures: Account Balance
    S_ALR_87012080 - Transaction Figures: Special Sales
    S_ALR_87012081 - Transaction Figures: Sales
    S_ALR_87012078 - Due Date Analysis for Open Items (Check with this, it fulfills ur requirement)
    S_ALR_87012103 - List of Vendor Line Items (Check with this, it fulfills ur requirement)
    S_ALR_87012083 - List of Vendor Open Items for Printing
    S_ALR_87012084 - Open Items - Vendor Due Date Forecast
    S_ALR_87012085 - Vendor Payment History with OI Sorted List
    S_ALR_87012104 - List of Cleared Vendor Items for Printing
    S_ALR_87012105 - List of Down Payments Open On Key Date - Vendors
    Regards,
    GOPI KRISHNA YANDRA

  • Debit & Credit Balance Query

    Hi Every One Im New Here..
    Firstly I Say .. If Im Post In Wrong Section Then Plz Move My Post. Its My First Post.
    Here Is My Question..
    I Have Two Tables.
    Please Tell Me How To Get Running Balance.
    Im Also Read Other Related Topic But Im Failed To Understand Plz Solve My Problem.
    Table Details Is Here !
    Table 1 : Users
    UID,Name,Description
    Table 2 : Balance
    BID,UID,Date,Dr,Cr,Description

    * I must say that you really do not invest on the question and gives us do all the work for you. This is bad! For example:
    >> You show us images, and tell us stories, what can we do with those? can we query an image? Instead of images you should post INSERT query with some sample data, as I did!
    I already wrote it in my forsy response! It was OK for first time, not for the continues discussion!
    ** In the next time please
    post queries to create the tables, and to insert some sample data, instead of "stories". It is faster and much more clear for us to see and if need reproduce the tables in our server in order to post a solution. This is example of
    what you should have post:
    >> You post "result that you want to get" without any result! what can we guess from this arrow?!?
    Why not to post the real result that you want to get, according to the sample data (which you did not post and we can only see in the image)?!?
    This is free supporting forum and you ask us too mu7ch in my opinion, while doing to little to help us to help you.
    If this is not what you need, then please start over and (1) post the create table query (2) post insert data queries that we will have the same data as the image (3) post the result that you want to get and not just a arrow.
    I think that this is what you need, please check if this help you:
    -- Current Balance
    select [UID],[Cr],[Dr], SUM(ISNULL([Cr],0)+ISNULL([Dr]*(-1),0)) OVER (partition by [UID] order by BID) as Current_Balance
    from Balance
    I hope this is helpful :-)
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • Help required regarding tunning the query mentioned

    HI all ,
    Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
    QUery :
    UPDATE WF_ITEM_ATTRIBUTE_VALUES WIAV SET WIAV.TEXT_VALUE = REPLACE(WIAV.TEXT_VALUE,:B1,:B2)
    WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT WIA.ITEM_TYPE, WIA.NAME
    FROM WF_ITEM_ATTRIBUTES WIA WHERE WIA.TYPE = 'URL'
    AND WIA.ITEM_TYPE = WIAV.ITEM_TYPE
    AND WIA.NAME = WIAV.NAME)
    AND WIAV.TEXT_VALUE IS NOT NULL
    AND INSTR(WIAV.TEXT_VALUE
    , :B1) > 0
    Plan :*
    <pre>
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | UPDATE STATEMENT | | 453 | 14496 | 284K|
    | 1 | UPDATE | WF_ITEM_ATTRIBUTE_VALUES | | | |
    |* 2 | FILTER | | | | |
    |* 3 | TABLE ACCESS FULL | WF_ITEM_ATTRIBUTE_VALUES | 453 | 14496 | 282K|
    |* 4 | TABLE ACCESS BY INDEX ROWID| WF_ITEM_ATTRIBUTES | 1 | 33 | 2 |
    |* 5 | INDEX UNIQUE SCAN | WF_ITEM_ATTRIBUTES_PK | 1 | | 1 |
    Predicate Information (identified by operation id):
    2 - filter(("SYS_ALIAS_2"."ITEM_TYPE","SYS_ALIAS_2"."NAME")= (SELECT /*+ */
    "WIA"."ITEM_TYPE","WIA"."NAME" FROM "APPLSYS"."WF_ITEM_ATTRIBUTES" "WIA" WHERE
    "WIA"."NAME"=:B1 AND "WIA"."ITEM_TYPE"=:B2 AND "WIA"."TYPE"='URL'))
    3 - filter("SYS_ALIAS_2"."TEXT_VALUE" IS NOT NULL AND
    INSTR("SYS_ALIAS_2"."TEXT_VALUE",:Z)>0)
    4 - filter("WIA"."TYPE"='URL')
    5 - access("WIA"."ITEM_TYPE"=:B1 AND "WIA"."NAME"=:B2)
    </pre>
    Index :*
    <pre>
    INDEX_NAME COLUMN_NAME
    APPLSYS WF_ITEM_ATTRIBUTE_VALUES_PK 1 ITEM_TYPE
    2 ITEM_KEY
    3 NAME
    </pre>
    regds
    Rahul
    Edited by: RahulG on Jan 2, 2009 10:47 PM
    Edited by: RahulG on Jan 2, 2009 10:48 PM

    RahulG wrote:
    HI all ,
    Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
    A few notes:
    1. Your query is using bind variables. If you're already on 9i or later (probably 9iR2 according to plan output), this statement will be subject to bind variable peeking and therefore the output of EXPLAIN PLAN is only of limited use, since the actual execution plan might be different and/or might be based on different cardinality estimates based on the actual bind values peeked at hard parse time. You can use the V$SQL_PLAN view to get the actual execution plan(s) if the statement is still cached in the shared pool, from 10g on DBMS_XPLAN.DISPLAY_CURSOR is available for that purpose.
    2. The execution plan posted suggests that only 453 rows will correspond to the filter criteria (but, as mentioned in 1. is based on an unknown bind variable value when using EXPLAIN PLAN), and probably therefore the optimizer didn't unnest the subquery but runs this as recursive FILTER query potentially for each row passing the filter criteria on the driving table WF_ITEM_ATTRIBUTE_VALUES. Depending on the actual number of rows this might be inefficient, and unnesting the subquery and turning it into a join might be more appropriate. This might accomplished e.g. by providing more representative statistics to the optimizer (are the statistics up-to-date?).
    Although you can't change the SQL you could try this manually by using the UNNEST hint to see if it makes any difference in the execution plan (and run time):
    WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT /*+ UNNEST */ WIA.ITEM_TYPE, WIA.NAME
    ...3. The composite index WF_ITEM_ATTRIBUTE_VALUES_PK can only be used on the first column ITEM_TYPE for effective index access, the NAME column would have to be used as filter on all index leaf blocks that would be found using a range scan on ITEM_TYPE. This might be quite inefficient, and/or might lead to a lot of rows/blocks that need to be visited in the table using this index access path.
    4. You could try to trace the execution by enabling extended SQL trace, e.g. using the (undocumented) DBMS_SUPPORT package in 9i. Running the "tkprof" utility on the generated trace file tells you the actual row source cardinalities (which can then be compared to the estimates of the optimizer) and - if the "waits" have been enabled - what your statement has waited for most.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Regarding the select query

    Hi Experts,
    I have a select query as follows:
    select field1 field2  from db1 into table it1.
    Now suppose the it1-field1 contains values a,b and c.
    Now I want to select fields a,b and c from another db table db2.
    Instead of hard coding like this:
    select a b c from db2 into table it2.....
    How can I do this?
    Points will be awarded.
    Regards,
    Soumya.

    Hi Soumya ,
    Pleas use FOR ALL ENTRIES syntax , in this way you can select the records from db2 which are available or selected in db1.
    Like Header And Item table.
    You select records frm header table . then for corres ponding header records you select from detail table db2 .....
    Condition is the field containg a,b,c  is key field in both tables ...
    Reward points if it helps you .
    Regards
    Amber S

Maybe you are looking for