Rewrite of the query

Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production version

Hello

I want to rewrite a query in a PL/SQL function that I inherited, which returns a list of e-mail addresses to send a notification by e-mail to.

The function as it is currently written is:

DECLARE
    reporttype  NUMBER;
    count1      NUMBER;
    count2      NUMBER;
    email_addr  VARCHAR( 255 );
BEGIN

    SELECT COUNT( * )
    INTO   count1
    FROM   project_report_type
    WHERE  project_id = :P51_PROJ_ID AND
           type_id IN (SELECT type_id FROM report_type);

    IF (count1 != 0) THEN
        SELECT COUNT( * )
        INTO   count2
        FROM   report_admin
        WHERE  type_id IN (SELECT type_id FROM report_type);

        IF (count2 != 0) THEN
            SELECT listagg(TO_CHAR(resources.resource_email), ', ') WITHIN GROUP (ORDER BY resources.resource_email)
            INTO   email_addr
            FROM   report_admin
            LEFT JOIN resources ON resources.resource_onepass_id = report_admin.user_onepass_id
            WHERE  report_admin.type_id IN (SELECT project_report_type.type_id
                                            FROM   project_report_type
                                            WHERE  project_report_type.project_id = :P51_PROJ_ID AND
                                            project_report_type.type_id IN (SELECT report_type.type_id FROM report_type)
                                           );

            RETURN email_addr;
        END IF;
    END IF;
END;




I'm sure this can be written much more effectively, but I don't know how.

The first charge is to determine if a record exists in the table PROJECT_REPORT_TYPE for the project from the front end page and the PROJECT_REPORT_TYPE. TYPE_ID exists in the REPORT_TYPE table.

If at least one record exists then determine if a record exists in the REPORT_ADMIN table where the REPORT_ADMIN TYPE_ID exists in the REPORT_TYPE table.

If there is at least one record of that result, then create a list of e-mail addresses of RESOURCE table join again on the table REPORT_ADMIN, where REPORT_ADMIN TYPE_ID exists in the PROJECT_REPORT_TYPE table.

I thought of two queries that don't COUNT (*) I could join these two tables together for the values of the query online, SELECT type_id FROM report_type, is a glance toward the top of the table. Therefore, values for TYPE_ID columns must come from the REPORT_TYPE table.

So, I thought that maybe:

SELECT count (*) FROM project_report_type INNER JOIN report_admin count1 ON project_report_type.type_id = report_admin.type_id WHERE project_report_type.project_id =: P51_PROJ_ID;

If I had all the records in this query, then get a list of e-mail addresses?

Can what information I provide?

Thank you

Joe

Hi, Joe,

It depends on what you want to do when no line is detected.

If you want that the function returns NULL if no line is detected, then simply:

Email_address RETURN;

If you want the function to return a fixed string, then you can do something like

RETURN NVL (email_address, '(aucune donnée trouvée) ");

Just what you want, you must execute a RETURN statement, so it would be unwise to put the RETURN statement in an IF block.

Tags: Database

Similar Questions

  • Impossible to activate the rewrite of the query, no error

    Hello

    I created a simple MV with activated query rewrite, and it works well. The MV is very simple:

    Mv_sales CREATE MATERIALIZED VIEW

    NOLOGGING

    REFRESH THE STRENGTH TO DEMAND

    ACTIVATE THE QUERY REWRITING

    AS

    SELECT

    s.cust_id,

    Sum (s.QUANTITY_SOLD) sold_qty,

    Sum (s.AMOUNT_SOLD) sold_amt

    S SALES

    GROUP BY s.cust_id

    ;

    I tested the mechanism of query rewriting, and everything works as expected.

    Now, I created an another MV with a motion very similar to the one above, but with several tables.

    An excerpt from the new query:

    SELECT...

    Of

    FACT_SALES_AND_MARKDOWNS FSM

    DIM_PRODUCT DP

    DIM_LOCATION DL

    DIM_DATE DD

    WHERE WSF. DIM_PRODUCT_KEY = DP. DIM_PRODUCT_KEY

    AND WSF. DIM_LOCATION_KEY = DL. DIM_LOCATION_KEY

    AND WSF. DIM_SALE_DATE_KEY = DD. DIM_DATE_KEY

    GROUP BY

    DD MERCH_YEAR_ID.

    DD. MERCH_YEAR_START_DATE...

    I can create the MV, but the query rewriting will not activate!

    If I execute ALTER materialized view mv_test ALLOW to REWRITE the QUERY. It runs without giving me an error, but the MV is not always activate the rewrite of the query.

    Am I missing something? Can we not have Query Rewrite on a MV with several tables in the query?

    Thank you

    Joao Moreira

    Hello

    Please provide the results of these queries:

    Select MVIEW_NAME, REWRITE_ENABLED

    of DBA_MVIEWS

    where MVIEW_NAME = '';

    Kind regards.

  • 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?

  • How can rewrite the query statement effectively

    Hi gurus,

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Release 10.2.0.4.0 - Production 64-bit

    PL/SQL Release 10.2.0.4.0 - Production

    CORE 10.2.0.4.0 Production

    AMT for Linux: release 10.2.0.4.0 - Production

    NLSRTL Version 10.2.0.4.0 - Production

    Table scripts


    CREATE TABLE WAREHOUSE

    (

    IDZONE VARCHAR2 (6 BYTE) NOT NULL,

    ZONE_CREATEDATE DATE NOT NULL,

    DATE OF DT_WAREHOUSE,

    DATE OF DT_POSTING

    )

    AREA ID, ZONE_CREATEDATE is PK

    CREATE TABLE ZONE_VIEW

    (

    IDZONE VARCHAR2 (6 BYTE) NOT NULL,

    ZONE_CREATEDATE DATE NOT NULL,

    ZONE_NUM NUMBER (2) NOT NULL,

    DATE OF TRANX_DATE

    )

    ID of the AREA, ZONE_CREATEDATE, ZONE_NUM is PK

    Query

    SELECT ID area, zone_createdate

    Of

    (

    SELECT ID area, zone_createdate,

    MAX (CASE WHEN zone_num = 18 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 18 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_18,.

    MAX (CASE WHEN zone_num = 110 AND not IS NOT NULL, THEN 1 TIME = 110 zone_num tranx_date AND tranx_date IS NULL THEN 0 ELSE-1 END) region_110,.

    MAX (CASE WHEN zone_num = 135 AND tranx_date no IS NOT NULL, THEN 1 TIMES zone_num = 135 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_135,.

    MAX (CASE WHEN zone_num = 140 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 140 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_140

    OF zone_view

    GROUP BY IDZone, zone_createdate

    ) zrn

    WHERE zrn.region_18 <>0

    AND (((zrn.region_110 = 1) OR (zrn.region_110 = - 1)) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_warehouse IS NULL)))

    AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))

    OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140 < 1))

    OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140, <>, 0))

    );

    Top query runs too slowly on the real data set. Is there an effective way to rewrite the query which can perform the dough?

    Any help or suggestion would be appreciated

    Thanks in advance

    At the time where the application may not throw anything until after he has retrieved and grouped all the ranks of zone_view. His estimate of 7.5 minutes to scan millions 639 lines really fast enough - it's 85 million lines per minute.

    This seems to be where the time went. The only way that the query can be accelerated is to recover some of the conditions that must be applied before the grouping. The only obvious possibilities for this are

    (a) filter values of zone_num

    (b) move the audit only

    NOT EXISTS (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_warehouse IS NULL)

    within the group, because this condition is applied regardless of the values in calculated fields. The AREA ID, ZONE_CREATEDATE are not null, so I suggest to try:

    SELECT ID area, zone_createdate

    Of

    (

    SELECT ID area, zone_createdate,

    MAX (CASE WHEN zone_num = 18 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 18 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_18,.

    MAX (CASE WHEN zone_num = 110 AND not IS NOT NULL, THEN 1 TIME = 110 zone_num tranx_date AND tranx_date IS NULL THEN 0 ELSE-1 END) region_110,.

    MAX (CASE WHEN zone_num = 135 AND tranx_date no IS NOT NULL, THEN 1 TIMES zone_num = 135 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_135,.

    MAX (CASE WHEN zone_num = 140 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 140 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_140

    OF zone_view

    where (IDZone, zone_createdate) NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)

    and zone_num (18, 110, 135, 140)

    GROUP BY IDZone, zone_createdate

    ) zrn

    WHERE zrn.region_18 <> 0

    AND ((zrn.region_110 = 1) OR (zrn.region_110 = - 1))

    AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))

    OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140)<>

    OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140 <> 0))

    )

    Unfortunately, if the plan of the query time estimates are correct, most of the duration of the query is spent doing a reading zone_view in a full analysis, and which will not be changed by this query.

    If there are many rows for each (IDZone, zone_createdate) zone_view pair, then it is possible that an index on (area ID, zone_num, zone_createdate) would contribute to this request, especially if most (IDZone, zone_createdate) pairs are filtered with the NOT IN (select the zone ID, zone_createdate w warehouse WHERE w.dt_warehouse IS NULL). More radical but probably effective measure would be a functional on index

    zone_view (zone_num, IDZone, zone_createdate, case when tranx_date is null then 0 otherwise 1 end)

    and using the expression in the query box:

    SELECT ID area, zone_createdate

    Of

    (

    SELECT ID area, zone_createdate,

    NVL (MAX (CASE WHEN zone_num = 18 then case when tranx_date is null, then 0 or 1 end end),-1) region_18,.

    NVL (MAX (CASE WHEN zone_num = 110 then case when tranx_date is null, then 0 or 1 end end),-1) region_110,.

    NVL (MAX (CASE WHEN zone_num = 135 then case when tranx_date is null, then 0 or 1 end end),-1) region_135,.

    NVL (MAX (CASE WHEN zone_num = 140 then case when tranx_date is null, then 0 or 1 end end),-1) region_140

    OF zone_view

    where (IDZone, zone_createdate) NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)

    and zone_num (18, 110, 135, 140)

    GROUP BY IDZone, zone_createdate

    ) zrn

    WHERE zrn.region_18 <> 0

    AND ((zrn.region_110 = 1) OR (zrn.region_110 = - 1))

    AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))

    OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140)<>

    OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140 <> 0))

    )

    This gives a very different plan on my database, by performing an iteration on relevant areas of performance status:

    ---------------------------------------------------------

    | ID | Operation | Name |

    ---------------------------------------------------------

    |   0 | SELECT STATEMENT |              |

    |*  1 |  FILTER                          |              |

    |   2.   VIEW                           |              |

    |*  3 |    FILTER                        |              |

    |   4.     HASH GROUP BY.              |

    |   5.      ANTI NESTED LOOPS.              |

    |   6.       INLIST ITERATOR.              |

    |*  7 |        INDEX RANGE SCAN | ZV_F1 |

    |*  8 |       TABLE ACCESS BY INDEX ROWID | WAREHOUSE |

    |*  9 |        INDEX UNIQUE SCAN | WAREHOUSE_PK |

    | * 10 |   TABLE ACCESS BY INDEX ROWID | WAREHOUSE |

    | * 11 |    INDEX UNIQUE SCAN | WAREHOUSE_PK |

    ---------------------------------------------------------

    Your plan will be different because you have data volumes (I didn't create millions of lines of test data)

    It would be useful to know how many rows there are in the WAREHOUSE, how many distinct (IDZone, zone_createdate) pairs there are in zone_view and the number of rows actually returns the query, and how much is NOT IN (select the zone ID, w zone_createdate warehouse WHERE w.dt_warehouse IS NULL) because these relative numbers determine how these approaches are.

    If there is a table containing all of the (area ID, zone_createdate) pairs which could take place in zone_view, which would have may another possible approach:

    First filter possible pairs against NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)

    Then attach them to the zone_view to retrieve only the rows in the filtered (IDZone, zone_createdate) pairs.

    Good luck.

  • Rewrite the query, select below or try to get the necessary O/P

    Hello..

    My example of data.,.

    Create table customer (name varchar2 (10), telephone1 telephone2 number (10), number of phone3 (10), (10) number, bitwisephone number (10));

    Insert into customer values('a',23456,67890,null,12345);

    Insert into customer values ('b', 67459,89760,null, 37689);

    create table do_not_call (dont_call number (10));

    insert into do_not_call values (67890);

    insert into do_not_call values (37689);

    Question: -.
    --------------

    Customer 'a' has value of numbers1 as 23456.check if telephone1 exists in the do_not_call table.
    In fact there is no, so set the bit for numbers1 as "o" like wise search telephone2
    & phone3.after update of the bitwisephone for each client should be as the output below.


    Need to O/P: -.
    -------------------

    name bitwisephone

    a 010
    b 001


    For that matter... I use "any" operator...



    SELECT name, case when numbers1 = all (SELECT dont_call FROM do_not_call) and then put an end to '1' other '0'.
    -case when telephone2 = all (SELECT dont_call FROM do_not_call) and then put an end to '1' other '0'.
    -case when phone3 = all (SELECT dont_call FROM do_not_call) then '1' other '0' end 'Bits '.
    OF THE customer;


    Is there any other way to get the necessary O/P?


    Thank you!!

    Kind regards
    VijayRajaram.

    Looks like one already answered Re: rewrite the query, select below or try to get the necessary O/P

    with
    customer(name,phone1,phone2,phone3,bitwisephone) as
    (select 'a',23456,67890,12345,null from dual union all
     select 'b',67459,89760,37689,null from dual
    ),
    do_not_call(dont_call) as
    (select 67890 from dual union all
     select 23456 from dual union all
     select 37689 from dual
    )
    select name,
           to_char(mod(trunc(sum(weight)/4),2))||
           to_char(mod(trunc(sum(weight)/2),2))||
           to_char(mod(sum(weight),2)) bitwisephone
      from (select name,phone1 phone,4 weight
              from customer
            union all
            select name,phone2,2
              from customer
            union all
            select name,phone3,1
              from customer
           ) c,
           do_not_call d
     where c.phone = d.dont_call(+)
       and d.dont_call is not null
     group by name
    

    Please do not duplicate messages

    Concerning

    Etbin

  • Rewrite the query with joins, and group by

    Hello

    It's an interview question.

    Table names: bookshelf_checkout
    virtual library

    And the join condition between these two tables is title

    We need to rewrite under request without using the join condition and group by clause?

    SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
               FROM bookshelf_checkout bc,bookshelf b
               WHERE bc.title(+)=b.title
               GROUP BY b.title;
    When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.

    Kindly help me on this.

    Thank you
    Suri

    Something like that?

      1  WITH books AS (
      2  SELECT 'title 1' title FROM dual UNION ALL
      3  SELECT 'title 2' FROM dual UNION ALL
      4  SELECT 'title 3' FROM dual ),
      5  bookshelf AS (
      6  SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
      7  SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
      8  SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
      9  SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
     10  UNION
     11  (SELECT b.title, NULL FROM books b
     12  MINUS
     13* SELECT bs.title, NULL FROM bookshelf bs)
    SQL> /
    
    TITLE   MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
    ------- ------------------------------------------------------------
    title 1                                                           14
    title 2                                                           44
    title 3
    

    Lukasz

  • Rewrite the query to improve the performance and the optimized below cost.

    Oracle 10g.

    ----------------------

    Query

    UPDATE FACETS_CUSTOM. MMR_DTL

    SET

    CAPITN_PRCS_IND = 2,

    FIL_RUN_DT = Current_fil_run_dt,

    ROW_UPDT_DT = dta_cltn_end_dttm

    WHERE CAPITN_PRCS_IND = 5

    AND HSPC_IND = 'Y '.

    AND EXISTS (SELECT 1

    OF FACETS_STAGE. CRME_FUND_DTL_STG STG_CRME

    WHERE STG_CRME. MBR_CK = MMR_DTL. MBRSHP_CK

    AND MMR_DTL. PMT_MSA_STRT_DT BETWEEN STG_CRME. ERN_FROM_DT AND STG_CRME. ERN_THRU_DT

    AND STG_CRME. FUND_ID IN ('AAB1', '1AA2', '1BA2', 'AAB2', '1AA3', '1BA3', ' 1 B 80 ', ' 1 HAS 80 '))

    AND EXISTS (SELECT 1

    OF FACETS_CUSTOM. FCTS_TMS_MBRID_XWLK XWLK

    WHERE XWLK. MBR_CK = MMR_DTL. MBRSHP_CK

    AND MMR_DTL. PMT_MSA_STRT_DT BETWEEN XWLK. HSPC_EVNT_EFF_DT AND XWLK. HSPC_EVNT_TERM_DT);

    Explain the plan of the query

    -----------------------------------------------

    Hash value of plan: 3109991485

    -------------------------------------------------------------------------------------------------------

    | ID | Operation | Name                  | Lines | Bytes | Cost (% CPU). Time |

    -------------------------------------------------------------------------------------------------------

    |   0 | UPDATE STATEMENT.                       |     1.   148. 12431 (2) | 00:02:30 |

    |   1.  UPDATE                       | MMR_DTL |       |       |            |          |

    |   2.   SEMI NESTED LOOPS.                       |     1.   148. 12431 (2) | 00:02:30 |

    |*  3 |    HASH JOIN RIGHT SEMI |                       |    49.  5488. 12375 (2) | 00:02:29 |

    |   4.     TABLE ACCESS FULL | FCTS_TMS_MBRID_XWLK |  6494 | 64940 |    24 (0) | 00:00:01 |

    |*  5 |     TABLE ACCESS FULL | MMR_DTL |   304K |    29 M | 12347 (2) | 00:02:29 |

    |*  6 |    TABLE ACCESS BY INDEX ROWID | CRME_FUND_DTL_STG |     1.    36.     5 (0) | 00:00:01 |

    |*  7 |     INDEX RANGE SCAN | IE1_CRME_FUND_DTL_STG |     8.       |     1 (0) | 00:00:01 |

    -------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    3 - access("XWLK".") MBR_CK "=" MMR_DTL. " ("' MBRSHP_CK")

    filter ("XWLK". "HSPC_EVNT_EFF_DT" < = INTERNAL_FUNCTION ("MMR_DTL". " PMT_MSA_STRT_DT') AND

    'XWLK '. "" HSPC_EVNT_TERM_DT "> = INTERNAL_FUNCTION ("MMR_DTL". "PMT_MSA_STRT_DT")) "

    5 - filter("CAPITN_PRCS_IND"=5 AND "HSPC_IND"='Y')

    6 filter (("STG_CRME". "FUND_ID" = "1 HAS 80 ' OR 'STG_CRME'." " FUND_ID "="1AA2"OR"

    'STG_CRME '. "FUND_ID"= '1AA3' OR 'STG_CRME'. "FUND_ID" = "1 B 80 ' OR 'STG_CRME'. '. "FUND_ID" = "1BA2" OR "

    'STG_CRME '. "FUND_ID"= "1BA3" OR "STG_CRME". "FUND_ID"= "AAB1" OR "STG_CRME". ("FUND_ID"="AAB2") AND

    'STG_CRME '. "" ERN_FROM_DT "< = INTERNAL_FUNCTION ("MMR_DTL". "PMT_MSA_STRT_DT") AND "

    'STG_CRME '. "" ERN_THRU_DT "> = INTERNAL_FUNCTION ("MMR_DTL". "PMT_MSA_STRT_DT")) "

    7 - access("STG_CRME".") MBR_CK "=" MMR_DTL. " ("' MBRSHP_CK")

    I could not optimize this query for best performance and optimized the cost... Can someone guide me on this.

    Thank you

    DS

    You think you're going to lines updates 85K, Oracle think it will update a line.

    At the time where the existence of the first test runs that oracle think already up to 49 lines, which is probably why he uses the loop join nested for the second test. (In your version of Oracle, the subquery introduced existence a very bad assumption (small) on the amount of data will survive).

    It is possible that you will get better performance if you hint Oracle using a hash join for testing the existence - and you might want to think what test will eliminate most of the data and that we can first force.

    Having said that, however, note that MMR_DTL research is a considerable fraction of the cost of the query - and an analysis is an easy thing for Oracle cost properly - if, despite your comments on update a column with a clue to this topic, you will find that the query can be more effective if you use an index. This is more likely to be the case if data ' WHERE CAPITN_PRCS_IND = 5 AND HSPC_IND = 'Y' "is well grouped (perhaps the latest data added to the table).". "  You could then reduce the cost of maintaining this index by creating an index based on a feature that indexes only the lines where the predicate are both true so that the 2 update deletes the index entries and allows the index remain as thin as possible.

    Concerning

    Jonathan Lewis

  • Rewrite the query without a clause EXISTS

    I would like to know another way to write the query without the EXISTS clause below. The main problem is with the inner query not allowing Java Hibernate to cache the results of the query.

    Select max (wt.wtime) wttme
    x wt.
    PIA,
    z g
    where wt.vid = v.vid and
    v.GID = g.gid and
    g.gname = "XXX" and
    not exists (select *)
    x wt1.
    y v1,.
    z g1
    where wt1.vid = v1.vid and
    v1. GID = g1.gid and
    G1.gname = "XXX" and
    (wt1.last_updated < (sysdate-. 0013) or)
    Upper (WT1. Error) '= t'
    )
    )

    z / / DESC;
    Name of Type Null
    GID NOT NULL NUMBER
    GNAME NOT NULL VARCHAR2 (100)
    ACTIVE NON-NULL CHAR (1)
    DATE OF UPDATE_DATE
    UPDATED_BY VARCHAR2 (50)

    GID GNAME UPDATE_DATE ACTIVE UPDATED_BY
    1 XXX Y 6 July 09 14:50:24 Test

    y / / DESC;
    Name of Type Null
    VID NOT NULL NUMBER
    VNAME NOT NULL VARCHAR2 (100)
    GID NOT NULL NUMBER
    ACTIVE NON-NULL CHAR (1)
    DATE OF UPDATE_DATE
    UPDATED_BY VARCHAR2 (50)

    VID VNAME GID UPDATE_DATE ACTIVE UPDATED_BY
    1 ICT 1 Y 6 July 09 14:50:24 Test
    arvato 2 1 O 6 July 09 14:50:24 Test

    / / DESC x;
    Name of Type Null
    VID NOT NULL NUMBER
    NUMBER OF WTIME
    ERROR VARCHAR2 (4000)
    NOT CLOSED NULL CHAR (1)
    LAST_UPDATED DATE

    VID WTIME LAST_UPDATED CLOSED ERROR
    1 65 N N 10 JUNE 09 00:00:00
    2 23 N N AUGUST 10 09 00:00:00

    Ken R says:
    What I would like to have is a query WITHOUT a clause EXISTS and to implement INSIDE logical query * (wt1.last_updated< (sysdate="" -="" .0013)="" or="" upper(wt1.error)='T' )*="" in="" the="" outer="">

    Well have a look at the two queries above then.

  • Tuning for sql join key table no consumer of the heavy use of the query processor

    Obligation comes to tunne prod of the query in

    high use of the query processor

    sql_id: fp79wb32h7a6t

    Module: AHC, P_PatientDQ()

    Cost: 7

    Elapsed time: hung

    Status: Hung, 35,253,460 day at 30 minute intervals

    -Create table

    create table ahc. PATIENTVISITS

    (

    ahcid NUMBER,

    visitId NUMBER,

    visitstatus NVARCHAR2 (100),

    visitdate DATE,

    visitintime DATE,

    visitouttime DATE

    )

    -Create/recreate the index

    create indexes ahc. F1_PATIENTVISIT_AHCID on ahc. PATIENTVISITS (AHCID, VISITID);

    create indexes ahc. VISITDATE_IDX on ahc. PATIENTVISITS (TRUNC (VISITDATE));

    First total number of table

    Select count (1) of

    Pvs AHC.patientvisits

    -Save County 1387485

    create table ahc. PATIENTDEPENDENTVISITS

    (

    ahcid NUMBER (19) not null,

    IDPack NUMBER (10) not null,

    visitId NUMBER (19) not null,

    dependentvisitid NUMBER (19) not null,

    isdiabetic NUMBER (2)

    )

    -Create/recreate the index

    create indexes ahc. K1_PATIENTDEPENDENT_AHCID on ahc. PATIENTDEPENDENTVISITS (AHCID);

    Total number of second table

    Select count (1) of

    AHC.patientdependentvisits POS

    -Save County 774599

    Original request:

    SELECT count (*)

    ACH. PVS PATIENTVISITS

    WHERE PVS. VISITID IN (SELECT POS. DEPENDENTVISITID

    ACH. PATIENTDEPENDENTVISITS POS

    WHERE POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0)

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    AND PVS. AHCID = 37

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for the original query

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, GOAL = ALL_ROWS7141636697
    AGGREGATION OF TRI141
    SEMI OF THE NESTED LOOPS7141636697
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS4125332954
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID39231643
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS3116303753
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID214180932

    After editing the query

    SELECT / * + FIRST_ROWS * / COUNT (1)

    ACH. PVS PATIENTVISITS

    JOIN THE AHC. PATIENTDEPENDENTVISITS POS ON PVS. VISITID = POS. DEPENDENTVISITID

    WHERE PVS. AHCID = POS. AHCID

    AND POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for change request

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, TARGET = TIP: FIRST_ROWS7141592577
    AGGREGATION OF TRI141
    NESTED LOOPS
    NESTED LOOPS7141592577
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS4116366464
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID314243643
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID21152932
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS3125226113

    here after I changed the query no display cost = 7 io wait = improvement also 7 can someone please help these

    How to adjust or rewrite lots of join not keys to multiple records on table table

    Thank you

    VSM

    you have not answered my question. Are you really calling it 35 million times in 30 minutes?

    If so, why?

  • setting the query

    Hello

    I need a few entries to grant the request below I'm not good in the part of tuning

    platform = x 2-2 qurter rack exadata, linux

    Scenario-> we have converted the non table(100gb) partition to the partition table using online redefinition and the sub query takes a long time (4 min), appreciated the inputs by rewriting the query to improve performance

    Select * from ODS_RBS #MOBCDR where trunc(ods_rbs#mobcdr_dst) = to_date ('01-25-2015', ' dd-mm-yyyy');

    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 291412148

    --------------------------------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |
    --------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |                |    25 M |  4580M |  3934K (29) | 00:02:10 |       |       |
    |   1.  RANGE OF PARTITION ALL THE |                |    25 M |  4580M |  3934K (29) | 00:02:10 |     1.   428.
    |   2.   HASH PARTITION ALL |                |    25 M |  4580M |  3934K (29) | 00:02:10 |     1.     2.
    |*  3 |    STORE TABLE FULL ACCESS | ODS_RBS #MOBCDR |    25 M |  4580M |  3934K (29) | 00:02:10 |     1.   856.
    --------------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    3 - storage (TRUNC (INTERNAL_FUNCTION("ODS_RBS#MOBCDR_DST")) = TO_DATE (' 2015-01-25 00:00:00 ',))
    'syyyy-mm-dd hh24:mi:ss"))
    Filter (trunc (INTERNAL_FUNCTION("ODS_RBS#MOBCDR_DST")) = TO_DATE (' 2015-01-25 00:00:00 ',))
    'syyyy-mm-dd hh24:mi:ss"))


    Statistics
    ----------------------------------------------------------
    0 recursive calls
    0 db block Gets
    7024253 compatible Gets
    7022727 physical reads
    0 redo size
    679097582 bytes sent via SQL * Net to client
    3702904 bytes received via SQL * Net from client
    336582 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    5048706 rows processed

    BR

    PMP

    Hi, PMP,

    you have a clue about your date column?

    Maybe a component base snap on 'trunc(ods_rbs#mobcdr_dst)' can help.

    concerning
    Kay

  • Query based ViewObject does pull not all attributes, when the query has 'WITH' clause

    Hello

    12.1.2 and 12.1.3 JDeveloper

    When we try to create a custom query based ViewObject, and the query clause of "with."

    So not all the columns selected in the query are appearing as attributes of the View object in the wizard.

    This is the query. And it performs very well in Toad.

    WITH dept_count AS)

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id)

    SELECT e.first_name AS employee_name,

    DC1.dept_count AS emp_dept_count,

    m.first_name AS manager_name,

    DC2.dept_count AS mgr_dept_count

    E employees,

    dept_count dc1,

    m employees,

    dept_count dc2

    WHERE e.department_id = dc1.department_id

    AND e.manager_id = m.employee_id

    AND m.department_id = dc2.department_id;

    Only the EmployeeName attribute is extracted from the query. It does not show the rest of the attributes in the VO Wizard.

    VO.png

    (I also tried to create a VO from the EntityObject class and make it editable as false, even in this case all attributes are not displayed.)

    I was wondering if something changed in 12 c?

    It works in 11.1.1.7

    (A friend of mine just asked me this).

    Thanks for any help.

    Sameer

    Jdev dislikes the syntax

    You can rewrite as

    SELECT e.first_name AS employee_name,

    DC1.dept_count AS emp_dept_count,

    m.first_name AS manager_name,

    DC2.dept_count AS mgr_dept_count

    E employees,

    (

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id) dc1,.

    m employees,

    (

    SELECT department_id, COUNT (*) AS dept_count

    Employees

    GROUP BY department_id) dc2

    WHERE e.department_id = dc1.department_id

    AND e.manager_id = m.employee_id

    AND m.department_id = dc2.department_id

    who must work and give you the same result.

    Timo

  • 2.1 EA1: Query Builder does not update the query to display the results

    When using the query designer, if you click view results to see the results of the current query, then return to "Select columns" or the tabs 'Create a Where Clause' change the query, the "View results" tab shows again the results of the original query, even if no tables or columns of the original query occurs. By clicking on the button run the report or by setting a refresh interval has no effect.

    On another note, the query designer again is not reentrant, because you cannot select (highlight a part where cursor in) a query, and then open the query for this request of change graphically Designer.

    Sentinel,

    The problem is known and is listed in the known issues in the release notes for the first users. We hope to have this sent to production.

    Returning Query Builder is always on our list of things to do. We intend to rewrite the Query Builder and examine a number of requests related to this function. I'm hoping to make it a priority for the next release.

    Sue

  • When, on my home page, I click on the link "transparent popup" in the query "did you mean: transparent popup", NO RESULTS appear in this new tab; How to solve?

    I had trouble due, apparently, to a file named popuptransparent [dot] xul, which I have 3 cases on my computer (Win XP/Firefox last v.). Using my window of AVG home page, I get "popuptransparent" (try to fix) and the results appear OK. But then when I click to a new tab, on the "transparent popup" link in the query "did you mean: transparent popup", NO RESULTS appear in this new tab. In addition, when I reload then the Panel of AVG which sought to 'popuptransparent' in the first place, it, too, shows now no results. Or a panel shows Google now no results. They show the quantity of results, but just white screens for the results themselves.

    Links https://support.mozilla.org/en-US/questions/948804?esab=a & as = aaq and https://support.mozilla.org/en-US/questions/952141?esab=a & as = aaq brings me. I re-installed Firefox v. 20.0.1 nothing works. How to fix?

    Should I remove it from my computer all 3 of these instances of xul [dot]?

    Regarding the problem of searching, you can check the extension "Disconnect"? I think it could affect the Google sites and third parties who use Google. You can disable or try its button Options here:

    Firefox orange (or the Tools menu) button > addons > Extensions category

    While you're there, you can disable all extensions essential and unrecognized. When in doubt, turn off.

    After restarting Firefox, did you notice a difference?

    Could you explain in more detail the next part?

    Should I remove it from my computer all 3 of these instances of xul [dot]?

    Is this something that came in a security sweep? What question do you think they are originally? They are located in a folder extensions?

  • I need to stop a download of the query, I thought a stand-alone application but turns require a higher level (FCPX) as a 'parent' and I do not who have, or want to buy.

    I need to stop a download of the query, that I thought a stand-alone application but turns require a higher level (FCPX) as a 'parent' and I do not have that, or I want to buy it.

    Motion IS a stand-alone application. It is mainly designed to make effects for Final Cut Pro X, but it is not necessary to have with FCPX nor is it necessary to have FCPX to create projects for other purposes. When you open the query, simply select project of work outside the FCPX motion. You can save regular projects of Motion anywhere on your system.

  • How to activate the query suggestions

    How the query suggestions can be enabled in the Firefox address bar?

    You're welcome... good to know you got it working.

Maybe you are looking for