Store the query results

Hi,
I have a sub-query,which occurs 8 times inside 8 different case conditions .Is there any way that i can execute it once and store the results for further use,,, so that next time i directly get the results of the query without having to parse it and execute it..I think this would improve the performance
The subquery is
WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset))Any suggestions ,help from all you masters.. i would be grateful

Here is the complete query
SELECT (CASE
           WHEN (NVL (mi.host_deal_nb, ' ') = ' ')
              THEN (SELECT host_deal_nb
                      FROM mif
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mi.host_deal_nb
        END
       ) hub_deal_no,
       (CASE
           WHEN (SUBSTR (NVL (mt.free_text2, 'XX,XXX'), 1, 2) = 'XX')
              THEN (SELECT SUBSTR (free_text2, 1, 2)
                      FROM mtf1000
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE SUBSTR (mt.free_text2, 1, 2)
        END
       ) system_code,
       (CASE
           WHEN (SUBSTR (NVL (mt.free_text2, 'XX,XXX'), 4, 3) = 'XXX')
              THEN (SELECT SUBSTR (free_text2, 4, 3)
                      FROM mtf1000
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE SUBSTR (mt.free_text2, 4, 3)
        END
       ) deal_code,
       CASE
          WHEN mi.mop = 'BOOK'
             THEN CASE
                    WHEN mt.db_acc_off = 'PH1'
                       THEN 'T'
                    ELSE 'TT'
                 END
          WHEN mi.mop = 'SWIFT'
             THEN 'TT'
          WHEN mi.mop = 'INTERO'
             THEN 'TT'
          WHEN mi.mop LIKE 'DRFT%'
             THEN 'DD'
          WHEN mi.mop LIKE 'CHEQ%'
             THEN 'CO'
          ELSE 'LP'
       END payment_method,
       mi.mid,
       DECODE (mi.orig_mop,
               'SWIFT', 'SWF',
               'INTRERO', 'GPS',
               'FEEDER', 'EBS',
               'LPS'
              ) iw_trns_type,
       DECODE (mi.orig_mt, NULL, mi.msg_type, mi.orig_mt) msg_type,
       DECODE (mi.orig_reference,
               NULL, mi.REFERENCE,
               mi.orig_reference
              ) REFERENCE,
       DECODE (mt.orig_rfb, NULL, mt.rfb, mt.orig_rfb) related_ref,
       mi.value_date, mi.origvaluedate,
       (CASE
           WHEN mt.acc_no IS NULL
              THEN (SELECT acc_no
                      FROM mtf1000
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mt.acc_no
        END
       ) debit_hub_acc_no,
       (CASE
           WHEN mt.acc_type IS NULL
              THEN (SELECT acc_type
                      FROM mtf1000
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mt.acc_type
        END
       ) debit_hub_acc_type,
       (CASE
           WHEN mi.dbcurrency IS NULL
              THEN (SELECT mi.dbcurrency
                      FROM mif
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mi.dbcurrency
        END
       ) debit_hub_acc_currency,
       (CASE
           WHEN mt.cr_acc_no IS NULL
              THEN (SELECT mt.cr_acc_no
                      FROM mif
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mt.cr_acc_no
        END
       ) credit_hub_acc_no,
       (CASE
           WHEN mt.cr_acc_type IS NULL
              THEN (SELECT mt.cr_acc_type
                      FROM mtf1000
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mt.cr_acc_type
        END
       ) credit_hub_acc_type,
       (CASE
           WHEN mi.crcurrency IS NULL
              THEN (SELECT mi.crcurrency
                      FROM mif
                     WHERE mid =
                              (SELECT childmid
                                 FROM mfamily
                                WHERE relation = 'FUNDCREDIT'
                                  AND parentmid IN (
                                         SELECT mid
                                           FROM batch_subset
                                          WHERE pk_batch_subset =
                                                            mi.pk_batch_subset)))
           ELSE mi.crcurrency
        END
       ) credit_hub_acc_currency,
       mi.cramount, mi.orig_currency, mi.orig_amount,
       (CASE
           WHEN (mt.fx_deal_tp = 'X')
              THEN mi.dbamount * mt.dr_side_rate_am
           ELSE (CASE
                    WHEN (mi.crcurrency <> mi.currency)
                       THEN mi.dbamount
                    ELSE (CASE
                             WHEN (mi.currency = mi.dbcurrency)
                                THEN (mi.dbamount * mt.cr_rate)
                             WHEN (mi.currency = mi.crcurrency)
                                THEN (mi.dbamount * mt.dr_rate)
                          END
                 END
        END
       ) rmt_amt_in_lcl_ccy_eqv,
       CASE
          WHEN mt.fx_deal_tp = 'X'
             THEN mt.dr_side_rate_am
          WHEN mi.crcurrency != 'PHP'
             THEN 1
          WHEN mi.currency = mi.dbcurrency
             THEN mt.cr_rate
          WHEN mi.currency = mi.crcurrency
             THEN mt.dr_rate
       END exchange_rate,
       (CASE
           WHEN mt.fx_deal_tp = 'X'
              THEN mt.cr_side_rate_am
        END) cross_rate, DECODE (mt.org_idcode, 'AC', mt.org_id, '') org_id,
       mt.org_bic, mt.org, mt.org_addr1, mt.org_addr2, mt.org_addr3,
       DECODE (mt.bnf_idcode, 'AC', mt.bnf_id, '') bnf_id, mt.bnf_bic, mt.bnf,
       mt.bnf_addr1, mt.bnf_addr2, mt.bnf_addr3, mt.obi, mt.charges,
       (SELECT CONTENTS
          FROM messagefreetext mr
         WHERE UPPER (fieldname) = 'Narrative_77B'
           AND mr.mid = mi.mid
           AND ROWNUM = 1) CONTENTS,
       mi.orig_sender, mi.service, mi.mop, mi.batch_msg_tp,
       mi.batch_payment_tp, mi.msg_class,
       (CASE
           WHEN (mt.fx_deal_tp = 'X')
              THEN mt.cr_side_rate_am
           ELSE mt.cr_rate
        END
       ) cr_amt_in_lcl_ccy,
       (CASE
           WHEN (mt.fx_deal_tp = 'X')
              THEN mt.cr_side_rate_am
           ELSE mt.cr_rate
        END
       ) exrate_cr_amt_lcl_ccy,
       (CASE
           WHEN (mi.non_stp = '1')
              THEN 'Y'
           ELSE 'N'
        END) non_stp_indicator
  FROM (SELECT mid
          FROM mif ssmi
         WHERE NVL (ssmi.pk_batch_subset, 999999) IN (
                  SELECT NVL (smi.pk_batch_subset, 0)
                    FROM mtf1000 smt, mif smi
                   WHERE smt.free_text2 IN ('AF,IDP', 'AF,XFR', 'AF,TFR')
                     AND smi.posting_status = 'SUCCESSFUL'
                     AND smt.mid = smi.mid)
           AND ssmi.batch_msg_tp = 'I'
        UNION
        SELECT ssmt.mid
          FROM mtf1000 ssmt, mif smmt
         WHERE ssmt.free_text2 IN
                  ('HE,TFR',
                   'IR,TTI',
                   'IR,TTB',
                   'IR,CO',
                   'IR,DD',
                   'IR,ITO',
                   'IR,IRT'
           AND ssmt.mid = smmt.mid
           AND smmt.posting_status = 'SUCCESSFUL') ts1,
       mif mi,
       mtf1000 mt
WHERE mi.posting_status = 'SUCCESSFUL'
   AND mi.msg_status = 'COMPLETE'
   AND NVL (mi.batch_payment_tp, ' ') NOT IN ('RTACH', 'ACHRT', 'DRO', 'DRI')
   AND mi.process_dt = TO_DATE ('20061222', 'YYYYMMDD')
   AND mi.office = 'PH1'
   AND ts1.mid = mi.mid
   AND mi.mid = mt.mid
   AND ((SELECT (CASE
                    WHEN (mif.complete_time >= memopost.update_date)
                       THEN (mif.complete_time)
                    ELSE (memopost.update_date)
                 END
           FROM mif, memopost
          WHERE mif.mid = mi.mid AND mif.mid = memopost.mid AND ROWNUM = 1) >
                      TO_DATE ('2008/02/05 10:12:24', 'YYYY/MM/DD HH24:MI:SS')
   AND ((SELECT (CASE
                    WHEN (mif.complete_time >= memopost.update_date)
                       THEN (mif.complete_time)
                    ELSE (memopost.update_date)
                 END
           FROM mif, memopost
          WHERE mif.mid = mi.mid AND mif.mid = memopost.mid AND ROWNUM = 1) <=
                      TO_DATE ('2008/03/06 20:00:00', 'YYYY/MM/DD HH24:MI:SS')
       )

Similar Messages

  • Store SQL query results in db table

    Hi,
    I have a SQL query that produces a report table.
    Is it possible to automatically store the query results (or the report table) as a db table - without interrupting the current report building proces?
    Thanks,
    Dave
    Message was edited by:
    Dave Judge

    Hi Dave,
    You can also insert records into an existing table:
    INSERT INTO TABLEB (colA, colB, colC, etc) SELECT valA, valB, valC, etc FROM VIEWA WHERE etc etc
    This can be done during a page process that runs "Before Header" and you can base your report on the TABLEB. Obviously, you will need to maintain that table to ensure that it is only truncated where necessary, that one user doesn't try to access another user's data on that table and that each time your page is loaded it doesn't try to repopulate the table when you don't need it to.
    Another possiblity is to use a collection - which is user session based
    Andy

  • How to get the query result of improvement (Before and After ) using sql de

    how to get the query result of improvement (Before and After ) using sql developer.

    Check
    http://www.oracle.com/technetwork/articles/sql/exploring-sql-developer-1637307.html

  • How to display the query results in several pages?.

    Hi,
    i want to display the query results in several pages. for example my query result found 50 matches, now i want to print 20 per pages next 20 will be in next pages. iam using only jsp & mysql.
    Regards
    Chinna

    Hi, what you are trying accomplish is known as pagination.
    You could use JSTL tags with Custom Tags to perform pagination in your JSP pages.
    evnafets showed me DisplayTags , you could use those as well http://displaytag.sourceforge.net/11/tut_externalSortAndPage.html
    Here is one article on paging:
    http://www.javaworld.com/javaworld/jw-07-2004/jw-0726-pagination.html

  • How to put variable selection and the query result the same screen

    Dear all,
       how can I put the variable selection and the query result in the same screen? Please advise. Thanks.
    Jin Ming

    Not sure if you are saying you want the prompts on the same page as the results... however in 7.0 with BEx Analyzer, you can insert a text object from the design toolbar and assign it to the variable.... this way, lets say you run query for period 6, then the text object will display "6" on the same area where the query results are.

  • Display the query result in an Excel file??

    hi there..
    am writing one script file that queries my DB and display the query result in an Excel file??
    i.e: if my query is :
    select col1, col2
    from table;
    and i want the results to dispalys in 2 col. in an Excel spreadsheet..
    Appreaciating ur cooperation..
    Mourad

    set colsep to a delimiter that is not normally part of your data like |
    also setup the environment with these other setup commands
    Set Echo Off;
    Set Concat Off;
    Set Pagesize 9999;
    Set Feedback Off;
    Set Verify Off;
    Set Term Off;
    Set Space 0;
    Set Colsep '|'
    Set Underline Off;
    If you wanted to use a comma delimiter the setup would be same but the set colsep='","'
    with the addition of concatenating a " on the first col and last col of the query
    eg.
    -- if first col and last_col are character types then
    SELECT '"'||col1,....,last_col||'"'
    FROM table;
    Otherwise if either is a number they would have to be converted with a TO_CHAR

  • During SQL query inserting a record - will it appear on the query result

    Hi,
    Oracle 10g SELECT-query executes ca 10 seconds and contains Joins over multiple tables in on database conenction.
    On execution 3rd second a new record is inserted in another database connection and commited to the database, the 3rd query satisgy the SELECT-Query fileters.
    Wil lthe inserted record on 3rd second appear on the query results?
    Thx.

    CharlesRoos wrote:
    Hi,
    Oracle 10g SELECT-query executes ca 10 seconds and contains Joins over multiple tables in on database conenction.
    On execution 3rd second a new record is inserted in another database connection and commited to the database, the 3rd query satisgy the SELECT-Query fileters.
    Wil lthe inserted record on 3rd second appear on the query results?
    Thx.In general Keith is right and a select will not see changes done and committed in a different session, that happend during the select. This is called READ CONSISTENCY. THis means a select will see the data from the exact time when it was called.
    However with database links in place read consistency can not be fully garanteed.
    See this explaination and solution from the 10g docs : http://docs.oracle.com/cd/B19306_01/server.102/b14231/ds_txnman.htm#i1008473

  • Why does the Query Result display "X" as a result

    Hello All,
    I have a query in which there are 6 Characteristics and 1 calculated key figure. But when the query is executed the query result displays as "X" in the column against all the 6 characteristics.
    Can anybody provide solution as to why the result displays "X" as a result.
    Regards,
    Vikram

    Hello all,
    Everybody answered it correctly. But when i debugged the query, i did not get any calculation which is getting divided by 0 and there were no mixed units of measurements. Probably it was an erroneous transport earlier. I only created and request again and transported the query from dev and the query is running fine.
    Thanks everybody.
    Vikram

  • RPD - Cannot obtain number of columns for the query result :Working with MS SQL 2012 schema

    Hi All,
    I have created my warehouse in MS SQL 2012.
    For management purpose, I have created different schemas in SQL database
    In RPD, Physical layer, when i view data > I get error as
    [nQSError:16002] Cannot obtain number of columns for the query result.
    [nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Invalid object name 'tbl'..
    [nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Statements could not be prepared..
    I have already browsed : OBIEE 11g Strange ODBC Driver Error with SQL Server : Total Business Intelligence ... did not help me
    please help!!!

    Hi All,
    After all R&D it is been found that Oracle business administrator( RPD) needs default dbo schema. It doesn't accept custom schema for pulling data.
    If anybody have other views please share.!!
    Thank you

  • Using CTRL + F not working to find any text within the query result

    Hi friends,
    I am trying to use find option to find any text within the result section of a query but when I do CTRL+F  the find window appears and I can input the text that I wanted. But when I press Enter it is not giving me any result though the entered text
    is in the query result. I am using Sql Server 2012 Management studio. Any Body please help me. There is a job that I have to search certain things after running a script and now I am doing copy paste to excel and doing searching from there. 

    Prashant,
    Looks like you are trying to do in SSMS, and it is because the result set is in Grid view , if you want to use CTL + F then your result should be in Text format, try to do using CTL + T ( To get result in Text) and then use CTL + F to find any
    text.
    Thanks
    Manish
    Please click Mark as Answer if my post solved your problem and click
    Vote as Helpful if this post was useful.

  • Using the client result cache without the query result cache

    I have constructed a client in C# using ODP.NET to connect to an Oracle database and want to perform client result caching for some of my queries.
    This is done using a result_cache hint in the query.
    select /*+ result_cache */ * from table
    As far as I can tell query result caching on the server is done using the same hint, so I was wondering if there was any way to differentiate between the two? I want the query results to be cached on the client, but not on the server.
    The only way I have found to do this is to disable all caching on the server, but I don't want to do this as I want to use the server cache for PL/SQL function results.
    Thanks.

    e3a934c9-c4c2-4c80-b032-d61d415efd4f wrote:
    I have constructed a client in C# using ODP.NET to connect to an Oracle database and want to perform client result caching for some of my queries.
    This is done using a result_cache hint in the query.
    select /*+ result_cache */ * from table 
    As far as I can tell query result caching on the server is done using the same hint, so I was wondering if there was any way to differentiate between the two? I want the query results to be cached on the client, but not on the server.
    The only way I have found to do this is to disable all caching on the server, but I don't want to do this as I want to use the server cache for PL/SQL function results.
    Thanks.
    You haven't provided ANY information about how you configured the result cache. Different parameters are used for configuring the client versus the server result cache so you need to post what, if anything, you configured.
    Post the code you executed when you set the 'client_result_cache_lag' and 'client_result_cache_size' parameters so we can see what values you used. Also post the results of querying those parameters after you set them that show that they really are set.
    You also need to post your app code that shows that you are using the OCI statements are used when you want to use client side result cacheing.
    See the OCI dev guide
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci10new.htm#sthref1491
    Statement Caching in OCI
    Statement caching refers to the feature that provides and manages a cache of statements for each session. In the server, it means that cursors are ready to be used without the need to parse the statement again. Statement caching can be used with connection pooling and with session pooling, and will improve performance and scalability. It can be used without session pooling as well. The OCI calls that implement statement caching are:
      OCIStmtPrepare2()
      OCIStmtRelease()

  • How to ensure that the query results are fetched from the BW acclerator.

    Hi Experts,
    Suppose if i want to execute the query with BIA option, I can achieve it in RSRT .
    1)But is there some query settings or properties where we can make sure that whenever a query(say Q1) is executed, always the data should be fetched from the BIA index.
    2)Suppose the BIA indexing has failed due  to some reasons, will the data be fetched from the previously updated BIA index??
    regards
    akshay

    Hi man,
    1)But is there some query settings or properties where we can make sure that whenever a query(say Q1) is executed, always the data should be fetched from the BIA index.
    If you have built up BIA index on a cube, then every query on the cube or MultiProvider will automatically use BIA index. No additional settings required. You can use the following way to test whether a query is using BIA or not:
    Go to RSRT, input query name, click 'execute and debug' and check 'Display Statistics Data' and 'Do Not Use Cache'. Execute. After the query result press F3, now you should be able to see statistics. There's a tab 'BIA Access'. If you see something there then it means BIA index is used.
    2)Suppose the BIA indexing has failed due to some reasons, will the data be fetched from the previously updated BIA index??
    If BIA rollup is failed, then the last request(s) would not available in reporting and query will use BIA index for earlier requests. You can consider it like aggregate. But if initial fill of BIA failed then you would not be able to use BIA index.
    Regards,
    Frank
    Edited by: Frank Lee on Jul 14, 2009 2:22 PM

  • Restricting the query result.

    Hello Experts ,
    Senario :
    I have Keyfigures 1)PO Line Item Count and 2) PO Value
    I want the number of PO Line Item having PO Value between 0 to 2,500$.
    I cant restrict a key figure with another keyfigure.
    Also in the query result i dont have any characteristic drilled, only key figure count is present.
    Please help.
    Thanks,
    Vinay

    Hi,
    Use RRI QUERY, Pass the query result of the first query to Second one and in the second query Use condition to display only       "Ito display the number of PO Line Item having PO Value between 0 to 2,500$."
    And Use "Count" function to display the number of Purchase Order Line items.
    Hope it helps...
    Regards.

  • Bug: the query results dialog extends outside the screen boundaries

    Hi, I observed this bug on MacOS 10.5.5 running Eclipse 3.4.1 with FlexBuilder 3.0.2 installed. Steps to repro:
    1. make FlexBuilder full screen
    2. open an MXML document
    3. make the editor full screen (double-click the editor's tab)
    4. select in the text editor the name of a Flex SDK class (e.g. Window, Button, ...)
    5. scroll the editor window so that the selected text is near the bottom of the screen
    5. click the Blueprint button, or type ctrl-B
    Result: the Blueprint query results window is only partly visible, most of it is below the bottom of the screen
    Expected: the query results window auto-positions itself to be fully visible

    Thanks for trying out Blueprint and giving us feedback!
    We have filed a ticket for this bug and will do our best to address it in the next release!
    Mira Dontcheva
    Research Scientist
    Adobe Systems

  • Styling report rows using the query result

    Hello, is it possible to style a row in a report using the values returned by the underlying sql query?
    For example, if my query returns a column called ROW_CLASS I would like to use the placeholder #ROW_CLASS# to style the row, e.g. specifying the row class.
    Apparently such row attributes are not available to the apex developer. For each single column value I can set the "Tabular Form Attributes" and "Column Formatting", but I cannot set anything on the whole row.
    In other words I can style the TDs but not the TRs.
    I think this is clearly a "missing feature" that should be there, single the APEX engine that turns the query result into the HTML that displays the table can already access the column values via their placeholders. It would be sufficient to add some "row attributes" or "row class" field in the report.
    It could be used for lots of useful things, in my particular case, highlighting rows that contain errors.
    Also there is no way to perform that operation in CSS (e.g. get the TRs which contain at least one TD of class "ROWERROR"). I know it could be done in JS, but that's very messy for such a simple declarative problem.

    GChierico wrote:
    Hello, is it possible to style a row in a report using the values returned by the underlying sql query? Yes, for standard reports, using custom report templates: +{thread:id=2493917}+
    Interactive reports require the use of Dynamic Actions/jQuery.

Maybe you are looking for