help query rewrite

Hello

could you help me rewrite the query without using joins

Select * from A, B, C
LEFT OUTER JOIN
WE (A.account_no = B.account_no
AND C.id_type = B.id_type
AND B.value = 1);


Thank you
-Raj

Select * from A, B, C
WHERE A.account_no = B.account_no (+)
AND C.id_type = B.id_type
AND B.value = 1;

Tags: Database

Similar Questions

  • Query rewrite

    Hello

    I have a report that I turn slowly. I know the problem, that this is due to a query that is called each time for each record. So, I need help to rewrite it.
    1. This is the first query
    
    SELECT id,
           t_id,
           p_id,
           a_date,
           d_date,
           u_dt,
           f_id,
      FROM xyz
     WHERE t_ind = 'N'
       AND s_cd IN (3, 5)
       AND p_id = '100177'
       AND d_date BETWEEN to_date('10/01/2008', 'MM/DD/YYYY') AND to_date('12/31/2008', 'MM/DD/YYYY')
       AND t_id IN (1,4)
    
     Now, for every id it calls same table in another function to get s_id. (2)
    
    2. 
    SELECT s_id
      FROM (SELECT lead(m.s_id, 0) over(PARTITION BY m.p_id, m.t_id, m.a_date, m.d_date ORDER BY m.u_dt DESC, m.f_id DESC) s_id,
             row_number() over(PARTITION BY m.p_id, m.t_id, m.a_date, m.d_date ORDER BY m.u_dt DESC, m.f_id DESC) row_num
              FROM xyz
             WHERE m.p_id = '100177'
               AND m.t_id = 4
               AND m.px_id = '001'
               AND m.a_date = to_date('01/25/2009', 'MM/DD/YYYY')
               AND m.d_date = to_date('02/07/2009', 'MM/DD/YYYY')
               AND m.s_id IS NOT NULL)
     WHERE row_num = 1;
    
    3. So, for every call for 1st query it calls second one and this is where problem lies. 
    How can combine us this time into one so that we have only a single call to this table to avoide several calls.
    so that we can include s_id in the same query.

    Maybe this?

    select xyz3,id,
           xyz3.t_id,
           xyz3.p_id,
           xyz3.a_date,
           xyz3.d_date,
           xyz3.u_dt,
           xyz3.f_id,
           xyz3.s_id
      from (SELECT xyz1.id,
                   xyz1.t_id,
                   xyz1.p_id,
                   xyz1.a_date,
                   xyz1.d_date,
                   xyz1.u_dt,
                   xyz1.f_id,
                   lead(xyz2.s_id, 0) over(PARTITION BY xyz2.p_id, xyz2.t_id, xyz2.a_date, xyz2.d_date
                                           ORDER BY xyz2.u_dt DESC, xyz2.f_id DESC) s_id,
                   row_number() over(PARTITION BY xyz2.p_id, xyz2.t_id, xyz2.a_date, xyz2.d_date
                                     ORDER BY xyz2.u_dt DESC, xyz2.f_id DESC) row_num
              FROM xyz xyz1,
                   xyz xyz2
             WHERE ((xyz1.t_ind = 'N') AND
                    (xyz1.s_cd IN (3, 5)) AND
                    (xyz1.p_id = '100177') AND
                    (xyz1.d_date BETWEEN to_date('10/01/2008', 'MM/DD/YYYY') AND to_date('12/31/2008', 'MM/DD/YYYY')) AND
                    (xyz1.t_id IN (1,4)))
               AND ((xyz2.p_id = xyz1.p_id) AND
                    (xyz2.t_id = xyz1.t_id) AND
                    (xyz2.px_id = xyz1.px_id) AND
                    (xyz2.a_date = xyz1.a_date) AND
                    (xyz2.d_date = xyz1.d_date) AND
                    (xyz2.s_id IS NOT NULL))) xyz3
     where xyz3.row_num = 1
    

    Note: not tested

  • How we force a query to use transparently a hint, even if the index is not given in the query as a query rewriting.

    How we force a query to use transparently a hint, even if the index is not given in the query as a query rewriting.

    For example:

    If the user runs a query select deptno, avg (sal) from emp group by deptno;

    We want the optimizer to use a hint of result_cache with this request, and it should be transparent to the user.

    Query should be rewritten to seamlessly

    Select / * + result_cache * / deptno, avg (sal)

    WCP

    Group of deptno;

    How can this feature we make? Please advice.

    I checked the possibility of SPM and contours, but it is not clear if this rewrite is possible here.

    Thank you and best regards,

    Vikas Krishna

    Surely dbms_advanced_rewrite is designed for this situation?

  • use of query rewriting

    is there a way to connect the materialized views how often are accessible in general or by the query rewriting enabled option?

    I would like to know what materialized views are useless, because they are never used by query rewrite.

    You can follow with select audit, good example here

    http://www.Oracle-base.com/articles/10G/auditing-10gR2.php

    If you want to in retrospect you may need something cludge together by hitting the v$ sql and plans to even see who has several SQL identifiers have a plan that rewrite. not good enough.

  • Help with Query Rewrite

    Hi guru,.

    First of all thank you very much for any help.

    I want to rewrite the query to make fast performance to retrieve the records. I'm passing date as parameter and its data donations for 1 week.

    I have an index on the column of rundate which I use in where clause. I select only forms a table in the entire query.

    Can you please help me to rewrite the request or suggestions.

    Thanks in advance!...
    SELECT  TO_CHAR(SYSDATE, 'MM/DD/YYYY') AS "GENERATED ON",
           to_char(TRUNC(:pdate, 'Day'), 'mm/dd/yyyy')  AS "FROM DATE",
           to_char(TRUNC(:pdate, 'Day') + 6, 'MM/DD/YYYY')  AS "TO DATE",
           TOTAL_CALLS AS "TOTAL CALLS",
           DEPARTMENT AS "DEPARTMENT",
           TOTAL_DEPTCALLS AS "TOTAL DEPARTMENT CALLS",
           START_DATE AS "START DATE",
           ORIGINAL_CATEGORY AS "ORIGINAL CATEGORY",
           ORIGINAL_SUBCATEGORY AS "ORIGINAL SUBCATEGORY",
           GROUP_ID AS "GROUP ID",
           GROUP_NAME AS "GROUP NAME",
           TOTAL_BY_CAT_SUBCAT AS "TOTAL BY CAT-SUBCAT",
           ROUND((TOTAL_BY_CAT_SUBCAT / TOTAL_CALLS) * 100, 2) AS "% TOTAL BY CAT-SUBCAT",
           TOTAL_BY_GROUP AS "TOTAL BY GROUP",
           ROUND((TOTAL_BY_GROUP / TOTAL_CALLS) * 100, 2) AS "% TOTAL BY GROUP",
           TOTAL_BY_GROUP_CAT_SUBCAT AS "TOTAL BY GROUP CAT-SUBCAT"
      FROM (SELECT DEPARTMENT AS "DEPARTMENT",
                   (SELECT count(1)  FROM PHONE_INQUIRY_CAUSE_REPORT RPT1
                             WHERE RPT1.RUNDATE >=  (TRUNC(:pdate, 'Day'))
                              and rpt1.rundate <= (TRUNC(:pdate, 'Day') + 6))
                               AS "TOTAL_CALLS",
                   CASE
                     WHEN DEPARTMENT = 'M' THEN
                     (SELECT count(1) 
                                 FROM PHONE_INQUIRY_CAUSE_REPORT RPT1
                                WHERE RPT1.RUNDATE >=  (TRUNC(:pdate, 'Day'))
                                 and rpt1.rundate <= (TRUNC(:pdate, 'Day') + 6)
                                  AND RPT1.DEPARTMENT = 'M')
                     WHEN DEPARTMENT = 'F' THEN
                      (SELECT count(1)
                                 FROM PHONE_INQUIRY_CAUSE_REPORT RPT1
                                WHERE RPT1.RUNDATE >=  (TRUNC(:pdate, 'Day'))
                                         and rpt1.rundate <= (TRUNC(:pdate, 'Day') + 6)
                                  AND RPT1.DEPARTMENT = 'F')
                   END AS "TOTAL_DEPTCALLS",
                   START_DATE AS "START_DATE",
                   ORIGINAL_CATEGORY AS "ORIGINAL_CATEGORY",
                   ORIGINAL_SUBCATEGORY AS "ORIGINAL_SUBCATEGORY",
                   GROUP_ID AS "GROUP_ID",
                   GROUP_NAME AS "GROUP_NAME",
                  (SELECT count(1)
                    FROM PHONE_INQUIRY_CAUSE_REPORT RPT2
                   WHERE RPT2.RUNDATE >= (TRUNC(:pdate, 'Day')) AND
                         RPT2.RUNDATE <= (TRUNC(:pdate, 'Day') + 6)
                     AND RPT2.ORIGINAL_CATEGORY = rpt.original_category
                     AND NVL(RPT2.ORIGINAL_SUBCATEGORY, '%') =
                         NVL(RPT.ORIGINAL_SUBCATEGORY, '%')
                    ) AS "TOTAL_BY_CAT_SUBCAT",
               (SELECT count(1)
                    FROM PHONE_INQUIRY_CAUSE_REPORT RPT2
                   WHERE RPT2.RUNDATE >= (TRUNC(:pdate, 'Day')) AND
                         RPT2.RUNDATE <= (TRUNC(:pdate, 'Day') + 6)
                    and rpt2.group_id = rpt.group_id
                 ) AS "TOTAL_BY_GROUP",
                 
                 (
             SELECT count(1)
                    FROM PHONE_INQUIRY_CAUSE_REPORT RPT2
                   WHERE RPT2.RUNDATE >= (TRUNC(:pdate, 'Day')) AND
                         RPT2.RUNDATE <= (TRUNC(:pdate, 'Day') + 6)
                     AND RPT2.ORIGINAL_CATEGORY = rpt.original_category
                     AND NVL(RPT2.ORIGINAL_SUBCATEGORY, '%') =
                         NVL(rpt.original_subcategory, '%')
                     AND RPT2.GROUP_ID = rpt.group_id
                )  AS "TOTAL_BY_GROUP_CAT_SUBCAT"
             FROM PHONE_INQUIRY_CAUSE_REPORT RPT
             WHERE RPT.RUNDATE >=  (TRUNC(:pdate, 'Day'))
             AND rpt.rundate <= (TRUNC(:pdate, 'Day') + 6)
             ORDER BY ORIGINAL_CATEGORY, GROUP_ID)

    Hello

    Try to use the function SUMMARY, rather than the aggregate COUNT:

    WITH    universe     AS
    (
         SELECT  department
         ,       COUNT (*) OVER ()          AS total_calls
         ,       CASE
                         WHEN  department IN ('F', 'M')
                      THEN  COUNT (*) OVER (PARTITION BY  department)
              END                            AS total_deptcalls
              ,       start_date
              ,       original_category
              ,       original_subcategory
              ,       group_id
              ,       group_name
              ,       COUNT (*) OVER (PARTITION BY  original_subcategory)
                                                     AS total_by_subcat
              ,       COUNT (*) OVER (PARTITION BY  group_id)
                                                  AS total_by_group
              ,       COUNT (*) OVER (PARTITION BY  original_subcategory
                                               ,           group_id
                                      )        AS total_by_subcat_group
         FROM    phone_inquiry_cause_report
         WHERE      rundate  >= TRUNC (:pdate, 'Day')
         AND      rundate  <  TRUNC (:pdate, 'Day') + 7
    )
    SELECT    TO_CHAR (SYSDATE,    'MM/DD/YYYY')     AS "GENERATED ON"
    ,         TO_CHAR (:pdate,     'MM/DD/YYYY')       AS "FROM DATE"
    ,         TO_CHAR (:pdate + 6, 'MM/DD/YYYY')       AS "TO DATE"
    ,         total_calls                           AS "TOTAL CALLS"
    ,         department
    ,         total_deptcalls               AS "TOTAL DEPARTMENT CALLS"
    ,         start_date                     AS "START DATE"
    ,         original_category                AS "ORIGINAL CATEGORY"
    ,         original_subcategory                AS "ORIGINAL SUBCATEGORY"
    ,         group_id                     AS "GROUP ID"
    ,         group_name                     AS "GROUP NAME"
    ,         total_by_cat_subcat                AS "TOTAL BY CAT-SUBCAT"
    ,         ROUND ( 100 * total_by_cat_subcat
                      / total_calls
              , 2
              )                    AS "% TOTAL BY CAT-SUBCAT"
    ,         total_by_group                AS "TOTAL BY GROUP"
    ,         ROUND ( 100 * total_by_group
                      / total_calls
              , 2
              )                    AS "% TOTAL BY GROUP"
    ,         total_by_group_cat_subcat           AS "TOTAL BY GROUP CAT-SUBCAT"
    ORDER BY  original_category
    ,            group_id
    ;
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • Need help on rewriting query for the DOMAIN CONTEXT index

    Hello

    I'd be really grateful if someone could give me a tip how to rewrite the query so that the DOMAIN INDEX is executed as the last and not the first... According to the plan to explain it...

    What I want: I want to index FIELD CONTAINS search for text ONLY for ITEMS that are extracted from the inner query (table MS_webarticlecache)...

    Because it seems now DOMAIN INDEx is executed first on all the MS_ARTICLE table and then filtered by inner query ID's...

    This query execution time is now around 86seconds... Inner query has all the indexes for SID_SUBCLIPPING and DATE_ARTICLE... (seen in line 3 of explain plan) If this one is fast and returns the unique id by grouping it and concating keywords...

    Without text... search results are retrieved in 3 seconds...

    DOMAIN index is created with Oracle 11 g FILTER BY ID, ART_DATE... and is on the MS_ARTICLE table and the ORATEXT seen on the sql column...

    Table MS_ARTICLE has 1.8mil lines...
    MS_WEBCACHEARTICLE table has cca. 2 lines of millet


    SQL:
    SELECT A.*, B.KEYWORDS OF
    MS_ARTICLE HAS
    JOIN THE
    (SELECT be, wm_concat (keywords) "KEY words" FROM MS_webarticlecache WHERE SID_SUBCLIPPING IN ('LEK', "KRKA") AND DATE_ARTICLE > = TRUNC(SYSDATE-400) AND DATE_ARTICLE < = TRUNC (SYSDATE) GROUP BY be) B
    WE
    A.ID = B.ID_ARTICLE AND CONTAINS (A.ORATEXT, 'IMMUNAL', 1) > 0

    Here is explain plan:
    Plan
    SELECT STATEMENT ALL_ROWSCost: 1 K bytes: cardinality K 16: 237
    1 FIELD INDEX INDEX (DOMAIN) PRESCLIP. ART_IDX cost: 120
    TABLE 2 ACCESS BY INDEX ROWID TABLE PRESCLIP.MS_ARTICLE cost: cardinality K bytes: 5 775: 237
    3 INDEX RANGE SCAN INDEX PRESCLIP. WEBCACHE_SUBCLIPDATE cost: cardinality 10: 964
    TABLE ACCESS BY INDEX ROWID TABLE PRESCLIP.MS_WEBARTICLECACHE cost 4: 250 octets: 45 K cardinality: 931
    5 INLIST ITERATOR
    Cost of 6 HASH JOIN: 1 K bytes: cardinality K 16: 237
    7 FILTER
    GROUP 8 SORT BY cost: 1 K bytes: cardinality K 16: 237


    Thank you very much for the help.
    Kris

    No, dbms_stats.gather_index_stats should be enough I think. From RECONSTRUCTION vs FULL - on rebuilding mode Oracle rebuilt just the table $I from scratch (it creates a temporary table, fills and then current exchanges and the new tables). It should be much faster that the FULL optimization, where the picture remains the same and only its content changes. The resulting table will be more compact, too.

  • Need help with rewrite of a query

    Hi friends,

    PFB the query and the result. Please ignore where the conditions, they are only about 50% accurate.

    SELECT XMLELEMENT ( 'majorLine' XMLATTRIBUTES ( ) d. ) line_id AS "Row Id" ),

    xmlforest (d. ) ordered_item as "itemName" , 

    d . ordered_quantity as 'quantity' ),

    (SELECT XMLAGG (XMLELEMENT ()"Service" XMLATTRIBUTES (e. ))) line_id AS Service ),

    ( ) SELECT XMLAGG (XMLELEMENT ( "ServiceName" ))

    XMLATTRIBUTES (of. ) ordered_item AS "ItemName" ),

    xmlforest (of. ) ordered_item as "itemName" , 

    de . ordered_quantity as 'quantity' )))

    DE oe_order_lines_all of

    de . line_id = e. line_id et de . link_to_line_id is null ))) 

    DE oe_order_lines_all e

    e. line_id = 143424538 ),

    (SELECT XMLAGG (XMLELEMENT ()"minorLine" XMLATTRIBUTES (e. ))) line_id AS minorLine ),

    ( ) SELECT XMLAGG (XMLELEMENT ( "itemName" ))

    XMLATTRIBUTES (of. ) ordered_item AS "ItemName" ),

    xmlforest (of. ) ordered_item as "itemName" , 

    de . ordered_quantity as 'quantity' )))

    DE oe_order_lines_all of

    de . line_id = e. line_id )))

    DE oe_order_lines_all e

    ( e. line_id = 143424538 ), (SELECT XMLAGG (XMLELEMENT ()"service" XMLATTRIBUTES (e. ))) line_id AS Service ),

    ( ) SELECT XMLAGG (XMLELEMENT ( "serviceName" ))

    XMLATTRIBUTES (of. ) ordered_item AS "itemName" ),

    xmlforest (of. ) ordered_item as "itemName" , 

    de . ordered_quantity as 'quantity' )))

    DE oe_order_lines_all of

    de . line_id = e. line_id et de . link_to_line_id is null ))) 

    DE oe_order_lines_all e

    ( e. line_id = 143424538 ( )

    ( ) YOU "dept_list"

    DE oe_order_lines_all d d . line_id = 143424538 ;



    The output is:


    < majorLine Line Id='143424538'>

    < itemName > 15454-TCC3-K9 = </ itemName >

    < quantity > 10 < / quantity >

    < Service SERVICE='143424538'>

    < ServiceName ItemName'15454-TCC3-K9 ='=>

    < itemName > 15454-TCC3-K9 = </ itemName >

    < quantity > 10 < / quantity >

    </ ServiceName >

    </ Service >

    < minorLine MINORLINE='143424538'>

    < itemName ItemName'15454-TCC3-K9 ='=>

    < itemName > 15454-TCC3-K9 = </ itemName >

    < quantity > 10 < / quantity >

    </ itemName >

    </ minorLine >

    < service SERVICE='143424538'>

    < serviceName itemName'15454-TCC3-K9 ='=>

    < itemName > 15454-TCC3-K9 = </ itemName >

    < quantity > 10 < / quantity >

    </ serviceName >

    </ service >

    </ majorLine >

    But the production expected as below

    < majorLine Line Id="143">

    < itemName > 15454-K = </ itemName >

    < quantity > 10 < / quantity >

    < Service >

    < lineId >143424538 < / lineId >

    < itemName > 15454-9 = </ itemName >

    < quantity > 10 < / quantity >

    </ Service >

    < minorLine MINORLINE='143424538'>

    < itemName > 1549 = </ itemName >

    < quantity > 10 < / quantity >

    </ minorLine >

    < service >

    < lineId >143424538 < / lineId >  

    < itemName > 159= </ itemName >

    < quantity > 10 < / quantity >

    </ service >

    </ majorLine >



    So the exact structure of XML output will be like that. In the example above, I didn't add the service of minors and several minor lines.

    I need to change the code above in the format below.



    < majorLine = "123456" LineID >-> there will be only one line of Major

    < itemNamme > MajorLineItem < / itemName >

    < quantity > 2 < / quantity >

    < service > -> there may be more than one service or no service of this major axis

    < > < lineId > 123456 lineId

    < itemNamme > serviceOfmajor < / itemName >

    < quantity > 2 < / quantity >

    < / service >

    < minorLine LineID '456789' = > -> there are several minor this major line lines

    < itemNamme > first_MinorlineItem < / itemName >

    < quantity > 7 < / quantity >

    < service >-> there may be more than one or NONE of the lines of service for one minor line

    < > < lineId > 11212 lineId

    < itemNamme > First_serivceOfMinor < / itemName >

    < quantity > 2 < / quantity >      

    < / service >

    < service >-> it may be more than one service lines for a line of minor

    < > 1347657 < lineId > lineId

    < itemNamme > second_serivceOfMinor < / itemName >

    < quantity > 2 < / quantity >      

    < / service >

    < minorLine LineID = "477838" > -> there are several minor this major line lines

    < itemNamme > second_MinorlineItem < / itemName >

    < quantity > 3 < / quantity >

    < / majorLine >



    Please help me to re - write the code. I used the approach of DOM node, its very long, I'm trying to replace it. Help, please. Let me know if you have any questions.


    Thank you and best regards,

    Arun Thomas T





    Not a Constructive Question.

  • Help on sql query rewriting

    Thank you

    Hello

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    Something not clear here:

    ... WHEN date_dim.date_key - CASE< 20150101="">

    If date_key is a DATE, so don't try to compare it to a NUMBER.

    If date_key isn't a DATE, then you have an even more serious problem.

  • Need help with Query Rewrite

    I have the SQL which contains a scalar subquery. I need to move the FROM clause scalar subquery. Please note that there is an OUTER JOIN in SQL.
    select CHDR.CHDRNUM POLICY_ID,
           CHDR.COWNNUM POL_OWNER,
           (Select Lifcnum
                     From Odslifeasia.Lifepf
                    Where Life = '01'
                      And Jlife = '00'
                      And Validflag <> '2'
                      AND CHDRNUM = CHDR.CHDRNUM
                      and rownum = 1) LIFE_ASSURED,
           CHDR.BILLCHNL,
          ( Select Facthous
             From Odslifeasia.Clbapf Clba, Odslifeasia.Mandpf Mand
            Where Clba.Validflag = '1'
              And Clba.Clntnum = mand.Payrnum
              And Clba.Clntcoy = Mand.Payrcoy
              And Clba.Bankacckey = Mand.Bankacckey
              And (Mand.Payrnum = Chdr.Payrnum Or
                  Mand.Payrnum = Chdr.Cownnum)
              And (Mand.Payrcoy = Chdr.Payrcoy Or
                  Mand.Payrcoy = Chdr.Cowncoy)
              And Mand.Mandref = Chdr.Mandref
              And Chdr.Billchnl In ('D', 'K', 'S')
              And Mand.Validflag = '1'
              And Mand.Mandstat = '10'
              and rownum = 1) Facthous,
               ACM_DATE,
              (Select Dc.Longdesc
              From Odslifeasia.Descpf Dc
             Where Dc.Descitem = CHDR.BILLCHNL
               And Dc.Desctabl = 'T3620'
               And DC."LANGUAGE" = 'E'
               And Dc.Desccoy = '2'
               And Dc.Descpfx = 'IT'
               And Rownum = 1) BILL_CHNL_NAME
           from odslifeasia.chdrpf chdr
           left outer join
             (SELECT chdrnum, MAX(DATESUB) acm_date FROM ODSLIFEASIA.PTRNPF
              WHERE PTRNPF.Batctrcde = 'B673' group by chdrnum) PTRN on (ptrn.CHDRNUM = chdr.CHDRNUM)
           where CHDR.VALIDFLAG IN ('1', '3');

  • Function Index and Query Rewrite

    Hi members,


    I just stumbled on something that I've never thought of before.

    It has to do with the function according to index and (possibly re - write query)

    Here is my configuration:
    SQL> create table tab1 (
      2    x   varchar2 (1)   default 'N' not null check (x in ('Y', 'N')),
      3    y   varchar2 (100) not null
      4  );
    
    Table created.
    
    SQL> create index tab1ix on tab1 (NULLIF(x,'N'));
    
    Index created.
    
    SQL> insert into tab1 (y)
      2    (select rpad (level,100,'x') from dual connect by level <= 1000);
    
    1000 rows created.
    
    SQL> insert into tab1 (x,y) values ('Y', 'Hello there');
    
    1 row created.
    
    SQL> commit
      2  /
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats(user, 'tab1', cascade => true)
    
    PL/SQL procedure successfully completed.
    So, I created a small table with a FBI.

    Now, let's use it.
    The first is a query that obviously do not use it.
    Second, one is a query that corresponds to the FBI.
    SQL> explain plan
      2     set statement_id = 'st1'
      3     into plan_table
      4  for
      5  select * from tab1 where x = 'Y';
    
    Explained.
    
    SQL> 
    SQL> select plan_table_output
      2    from table(dbms_xplan.display('PLAN_TABLE', 'st1','TYPICAL'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    ----------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost  |
    ----------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |   501 | 51603 |     5 |
    |   1 |  TABLE ACCESS FULL| TAB1 |   501 | 51603 |     5 |
    ----------------------------------------------------------
    
    
    SQL> explain plan
      2     set statement_id = 'st2'
      3     into plan_table
      4  for
      5  select * from tab1 where NULLIF(x,'N') = 'Y';
    
    Explained.
    
    SQL> 
    SQL> select plan_table_output
      2    from table(dbms_xplan.display('PLAN_TABLE', 'st2','TYPICAL'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    ----------------------------------------------------------------------
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost  |
    ----------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |        |     1 |   103 |     1 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| TAB1   |     1 |   103 |     1 |
    |   2 |   INDEX RANGE SCAN          | TAB1IX |     1 |       |     1 |
    ----------------------------------------------------------------------
    
    SQL> 
    No worries, right?
    Everything works as expected, when my predicate corresponds to the FBI, the index is used.


    But here's what surprises me. It seems that the index expression is rewritten then it is created:
    SQL> select column_expression from user_ind_expressions
      2  where index_name = 'TAB1IX';
    
    COLUMN_EXPRESSION
    --------------------------------------------------------------------------------
    CASE "X" WHEN 'N' THEN NULL ELSE "X" END
    
    SQL>
    Questions are now, is this safe? -Does still work?

    Can I trust the optimizer always did a rewrite such as performed when the index was created?


    This index might live throughout the years and many versions of the optimizer. But the expression stays (I guess)

    This is going into production this weekend, so I wanted to hear,
    ideas / comments?


    Best regards
    Peter
    SQL> select *from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Linux: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    PS: NULLIF is nothing else than a syntactic sugar for the CASE expression equivalent?
    docs say:
    The NULLIF function is logically equivalent to the following CASE expression:

    CASE WHEN expr1 = END expr1 expr2 THEN NULL ELSE
    edited by: Peter on February 9, 2012 05:32

    Hi Peter

    In the docs for NULLIF, he said

    The NULLIF function is logically equivalent to the following CASE expression:

    CASE WHEN expr1 = expr THEN ELSE NULL expr1 END 2

    http://docs.Oracle.com/CD/B10501_01/server.920/a96540/functions85a.htm
    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/functions102.htm
    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions116.htm

    Which would explain the behavior you saw. As you pointed out, it is possible that the transformation of NULLIF expression BOX equivalent is likely to change? It seems unlikely - indeed, it seems to be an alias or a macro for the instruction box unless there is some way technically superior to implement this logic, it seems to be here to stay. Certainly, it has remained unchanged since the 9i.

    Not sure how that helps.

    David

  • Model query rewriting, CLOSE, max_span

    Hi all

    I tried looking for this answer, so I hope that I have not forgotten the solution in the forum.

    For a query such as the following, how would I set the max_span value with NEAR?
    select id from docs where CONTAINS (text,
     '<query>
       <textquery lang="ENGLISH" grammar="CONTEXT"> kukui nut
         <progression>
           <seq><rewrite>transform((TOKENS, "${", "}", "AND"))</rewrite></seq>
           <seq><rewrite>transform((TOKENS, "${", "}", "NEAR"))</rewrite></seq>
         </progression>
       </textquery>
      <score datatype="INTEGER" algorithm="COUNT"/>
    </query>')>0;
    The following was something I tried to set the value of max_span to 20 words, but not surprisingly, it did not work :)
    <seq><rewrite>transform((TOKENS, "${", "}", "NEAR", "20"))</rewrite></seq>
    Any help would be appreciated!

    Hello

    I think that it is not possible in this way. If you look at the description of the TRANSFORMATION function:

    TRANSFORM((terms, prefix, suffix, connector))
    

    so I don't see any possibility to form TOKENS to something like ' near ((token1,token2), 20). It is not possible with this function.

    Maybe the only opportunity to do automatically is perhaps to use a self written function that returns the text of your rewrite.

    select id from docs where CONTAINS (text,
    your_rewrite_function('kukui nut') ) > 0
    

    In your_rewrite_function, you return a valid syntax.

    Herald tiomela
    http://htendam.WordPress.com

  • Code help: query based cfloop with StartRowOptional and EndRowOptional in cfscript

    It is probably a fairly simple thing - but I'm trying to learn as much cfscript possible by converting my CFC cfscript. I found examples of loops in cfscript based on a query, but I don't know where the StartRowOptional and EndRowOptional would fit in.

    < cfloop query = StartRowOptional "qQuery" = "start #" EndRowOptional = "#end #" >

    < cfset var = var1 >

    < cfset var2 = var2 >

    < / cfloop >

    Thanks a bunch for advice.

    ~ Ben

    You should be able to use a 'for' with indexes and keys. Something like (where 'start' and 'end' is your values):

    Loop over the query.

    for (intCurrentRow = start; end LTE intCurrentRow; intCurrentRow = (intCurrentRow + 1))

    {

    access the query as if it were a structure of arrays with the index of the current line:

    stcSongs.songID = qSongs ["songID'] [intCurrentRow];

    stcSongs.songName = qSongs ['songName'] [intCurrentRow];

    etc...

    }

    Hope that helps.

  • Advanced query rewrite does nothing

    Hello

    on Oracle 11 g R1, with a normal user who has EXECUTE on DBMS_ADVANCED_REWRITE privilege, I tried the following:
    CREATE TABLE REWRITE_TEST (
       "A" VARCHAR2(4000 BYTE),
       "B" NUMBER(38,0)
    );
    INSERT INTO REWRITE TEST (A, B) VALUES ('Hallo Welt!', 42);
    INSERT INTO REWRITE TEST (A, B) VALUES ('Noch mehr Daten', 43);
    COMMIT;
    
    BEGIN
    SYS.DBMS_ADVANCED_REWRITE.DECLARE_REWRITE_EQUIVALENCE (
       'TEST_OHNESEMIKOLON',
       'SELECT A FROM REWRITE_TEST',
       'SELECT ''HIHI'' FROM REWRITE_TEST',
       FALSE,
       'GENERAL');
    END;
    /
    
    SELECT A FROM REWRITE_TEST;
    gives the following result:
    A                                                                                                                                                        
    -----------------------------------------------------------------------------------------------------------
    Hallo Welt!                                                                                                                                                     
    Noch mehr Daten 
    that is the rewrite of the query does not. The anonymous block with DECLARE_REWRITE_EQUIVALENCE was executed without errors, so I guess it should work. I have really no idea what I'm doing wrong. Someone else has already tried this feature and did a job? Is there an obvious error in my code?

    Kind regards

    Christian

    Christian Menke says:
    Alex, long-term I need tune Oracle MapViewer with this, even if it now seems to be 'weird', it is really intended for productive use.

    are there no other ways to resolve Mapviewer?...
    Of course, I understand that you would not use it the way you have published it, but it just reminded me of the blogpost...

    What is the setting of the query_rewrite_integrity?
    Try this in your session:

    alter session set query_rewrite_integrity = trusted
    
  • Help query MySQL DW

    I am fairly new to DW and MySQL. I'm developing what I thought was a simple app search and results, but am apparently having a problem of program logic

    I have a form with 2 radio buttons, the code below:

    < name of the form = "card_search" id = "card_search" method = "post" action = "card_search_results.asp" >
    < p >
    < label >
    < input < % if (CStr ((rsCardCatBaseball.Fields.Item("catID").) (Value)) = CStr("1")) then Response.Write ("CHECKED"): Response.Write("") % > type = "radio" name = "RadioGroupCardCat" value = "1" / >
    Baseball < / label >
    < br / >
    < label >
    < input < % if (CStr ((rsCardCatBaseball.Fields.Item("catID").) (Value)) = CStr("2")) then Response.Write ("CHECKED"): Response.Write("") % > type = "radio" name = "RadioGroupCardCat" value = "2" / >
    Football < / label >
    < br / >
    < input name = "submit_card_cat" type = "submit" id = "submit_card_cat" value = "Submit" / >
    < /p >
    < / make >

    When testing using the URL GET param. I see that the RadioGroupCardCat var = 1 (baseball) or RadioGroupCardCat = 2 (football) go directly to the page card_search_results.asp. However, I can't understand how to capture the values of RadioGroupCardCat (1 or 2) in my SQL queries. I currently have 2 recordset of applications (rsCardCatBaseball and rsCardCatFootball) below.

    rsCardCatBaseball:

    SELECT tblcard.cardyear, tblcardvend.vendname, tblcard.cardnum
    OF tblcard, tblcardcat, tblcardvend
    WHERE RadioGroupCardCat = 1 AND tblcardvend.vendid = tblcard.vendid AND tblcardcat.catid = tblcard.catid

    rsCardCatFootball:

    SELECT tblcard.cardyear, tblcardvend.vendname, tblcard.cardnum
    OF tblcard, tblcardcat, tblcardvend
    WHERE RadioGroupCardCat = 2 AND tblcardvend.vendid = tblcard.vendid AND tblcardcat.catid = tblcard.catid

    "catid" corresponds to the field in MySQL table with a value of 1 (baseball) or 2 (football). I am using ASP/VBScript, so here's how the variable is declared in the variable box DW Recordset.

    FOR rsCardCatBaseball:

    NAME
    RadioGroupCardCat

    DEFAULT VALUE
    1

    RUNNING VALUE
    Request ("CATID")

    For rsCardCatFootball:

    NAME
    RadioGroupCardCat

    DEFAULT VALUE
    2

    RUNNING VALUE
    Request ("CATID")

    The problem is that I get the same results for both queries. The rsCardCatFootball query results are identicle to the rsCardCatBaseball query. Don't I just assumed to have 2 recordsets separate in the results page so that it went from a value and other RS Gets the value else? Any help is appreciated. Thank you.

    Thanks for the reply. I finally found the answer to my question at:

    http://www.Adobe.com/support/UltraDev/building/multiple_param_search/multiple_param_search 05.Marco html

    The declaration of variable in my SQL and DW statement were incorrect. I highly recommend the tutorial above for everyone new to DW and MySQL. The link above specifically explains how to create a variable to be used in a DW/MySQl app. thank you!

  • Need help query subquery

    Hey guys,.
    I have a question that I can't wrap my head around. I have a table called traffic, and in this table I have tons of columns... I focus mainly on three pillars, VIOLATIONTYPE, TID, AND guid. When a judgment is made, it receives a uniqueIdm which is the GUID column.
    If more than one ticket is given to the individual, the guid remains the same. I need to write a query to find out how many warnings is emitted by the user who is TID column.
    The problem is, if more than one ticket has been assigned at the time of the stop and these tickets are not only attention, but also a quote, I won't count that stops traffic in my query.
    I just need all the stops that are strictly warnings.
    Of course, I know how to extract the warnings, but if the guid is a warning and reference both, I don't know how to remove the records in the query. Any help would be appreciated. The query below, I wrote is just the initial steps to get * him to stop before I eliminate records where a quote and a caveat had the same GUID...

    Select * from traffic where tid = "1234" and violationtype = "warning" and guid in (select traffic seq_guid b where a.guid = b.guid)

    Consider using a NOT IN or NOT EXISTS a subquery to allow lines with citations, something like (not tested)

    select *
      from traffic a
     where tid='1234'
        and violationtype = 'warning'
        and guid in (select seq_guid from traffic b where a.guid = b.guid)
        and not exists (select 0 from traffic c where c.guid = a.guid and violation_type = 'citation')
    

Maybe you are looking for

  • OMEN of HP for laptop - 15-5001na: I need all applications for an omen of HP

    Can I have applications for my laptop (HP Omen) please. I restarted my laptop which means that I deleted my apps and I tried to install all my apps but I unfortunately couldn't find the Apps that I got when I started to use my laptop for example, I c

  • A700 touch screen no longer works

    All of a sudden the touch screen on my A700 has stopped working. I tried to update the drivers (I think elo Tyco Electronics TeTouchPlus v 1.4.0 is installed). The screen takes the input during calibration, but after that the touch screen has no impa

  • S206 - installation of xp, 0x0000007b bug, I need driver

    Hello i; m triying to install xp on my lenovo s206 and she came to rest on a blue creen saying Stop: 0x0000007b I saw on the web that I need to press f6 at the beginning to install a driver for my hard drive, but I don't know how can you help me plea

  • Photosmart 7280 stopped printing

    Photosmart 7280 is connected to the HP desktop Windows 7 ultimate (upgrade from Vista) suddenly not printing. When press print icon, message flashes on the screen as if she sent the document to the printer.  Check the print queue says no document. Sc

  • GED-125 Document

    Anyone know where I can get the GED-125 document, that I can't find on CISCO. Concerning Irfan Tariq