How to rewrite this query

How can i rewrite this query so it uses less inner joins (it causes my temp space to explode :) )
( SELECT Waardes.*, Tellers.Nr_Dataitems, Tellers.Nr_Details FROM
( SELECT extractvalue(Value(el_node), 'Node/Id') node,
extractvalue(Value(el_dataitem), 'Detail/Title') Node_Title,
extractvalue(Value(el_dataitem), 'Detail/Value') Node_Value
FROM PHILIPS_XML x,
TABLE (xmlsequence (extract (value(x), '/Tree/Node'))) el_node,
TABLE (xmlsequence (extract (value(el_node),
'Node/DataItems/DataItem/DetailSet/Detail'))) el_dataitem
) Waardes
INNER JOIN
SELECT A.Node, A.Nr_Dataitems, B.Nr_details FROM
SELECT extractvalue(Value(el_node), 'Node/Id') node,
count(extract(Value(aaa), 'DataItem')) Nr_Dataitems
FROM PHILIPS_XML x,
TABLE (xmlsequence (extract (value(x), '/Tree/Node'))) el_node,
TABLE (xmlsequence (extract (value(el_node),
'Node/DataItems/DataItem'))) aaa
GROUP BY extractvalue(Value(el_node), 'Node/Id')
) A
INNER JOIN
SELECT extractvalue(Value(el_node), 'Node/Id') node,
count(extract(Value(bbb), 'Detail')) Nr_details
FROM PHILIPS_XML x,
TABLE (xmlsequence (extract (value(x), '/Tree/Node'))) el_node,
TABLE (xmlsequence (extract (value(el_node),
'Node/DataItems/DataItem'))) aaa,
TABLE (xmlsequence (extract (value(aaa),
'DataItem/DetailSet/Detail' ))) bbb
GROUP BY extractvalue(Value(el_node), 'Node/Id')
) B
on A.node = B.NODE
) Tellers
ON Waardes.NODE = Tellers.NODE )

1st Make sure all paths are absolute (start with '/', not just the node name).
Which release are you using.. Is the document based on an XMLSchema, if so, what annotations were used when registered the XML Schema ?. What does the explain plan look like...

Similar Messages

  • How to rewrite this query without sub query please help me

    Hello All Good Evening,
    Could you please help me with this query, how can i write this query without sub query, or how can write this query another ways
    please help me
    select planno, status1, count(*) Counts from
    select a.ValetNO PlanNo  ,
    case 
         when JoinCode in ('00', '01', '02') then 'Actcess'
         when JoinCode in ('20', '21', '22', '23','38', '39') then
         'Secured' else 'Other' end Status1 ---, COUNT (*)
       from  dbo.ppt a(NOLOCK)  left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO  = b.ValetNO
    --group by a.ValetNO
      a group by planno, status1
    order by 2
    Thank you in Advance
    Milan

    Whats your objective here? Sorry, am not able to understand the reason for this change. 
    Try the below:(Not tested)
    ;With cte
    As
    select a.ValetNO PlanNo ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end Status1 ---, COUNT (*)
    from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
    select planno, status1, count(*) Counts from cte
    a group by planno, status1
    order by 2
    Even below:
    select a.ValetNO PlanNo ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end Status1 , COUNT (1)
    from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
    Group by a.ValetNO ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end

  • How to rewrite this query to avoid duplicates , please

    Hello Good Morning All,
    Happy New Year,
    Could you please help to rewrite the below two queries (so that i can avoid duplicates) i need to send email to everyone not the dupllicated ones), please?
    Create table #MyPhoneList
     AccountID int,
     EmailWork varchar(50),
     EmailHome varchar(50),
     EmailOther varchar(50),
     IsOffersToWorkEmail bit,
     IsOffersToHomeEmail bit,
     IsOffersToOtherEmail bit,
     IsValidEmailWork bit,
     IsValidEmailHome bit,
     IsValidEmailOther bit
    --> In this table AccountID is uniquee
    --> email values could be null or repetetive for work / home / Other (same email can be used more than one columns for accountid)
    -- a new column will be created with name as Sourceflag( the value could be work, Home, Other depend on email coming from) then removes duplicates
    SELECT AccountID , Email, SourceFlag, ROW_NUMBER() OVER(PARTITION BY AccountID, Email ORDER BY Sourceflag desc) AS ROW
    INTO #List
    from (
      SELECT AccountID
         , EmailWork      AS EMAIL
         , 'Work'       AS SourceFlag
      FROM #MyPhoneList (NoLock) eml
      WHERE IsOffersToWorkEmail    = 1
      AND  EMAILWORK      IS NOT NULL
      AND  IsValidEmailWork    = 1
     UNION
      SELECT AccountID
         , EmailHome  
         , 'Home'       AS SourceFlag
      FROM #MyPhoneList (NoLock) eml
      WHERE IsOffersToHomeEmail    = 1
      AND  EMAILHOME      IS NOT NULL
      AND  IsValidEmailHome    = 1
     UNION
      SELECT AccountID
         , EmailOther  
         , 'Other'       AS Sourceflag
      FROM #MyPhoneList (NoLock) eml
      WHERE EmailOther      = 1
      AND  EMAILOther      IS NOT NULL
      AND  IsValidEmailOther    = 1
     ) eml --select count(*) from #email
    --Email dedupe on source
    SELECT * INTO #distinct FROM #List WHERE ROW  = 1
    Thank you in Advance
    Milan

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> Could you please help to rewrite the below two queries (so that I can avoid duplicates) I need to send email to everyone not the duplicated ones), please? <<
    This mess is not a table because it has no keys, not way to have a key. You are using UNION like we used punch card merges in the o9ld days. 
    What math do you do on the account_id? That is the only reason that you use numeric values Why do you think that an email is fifty characters long? Yes, most them are, but did you bother to look at the maximum length? NO! Why did you name it “Phone_List” when
    it is nothing but email addresses? emails are not phones.  
    Please read this article so you will know why RDBMS does not use assembly language flags like you are doing. 
    https://www.simple-talk.com/sql/t-sql-programming/bit-of-a-problem/
    It would also help if you know what normalization was. Here is one design that is valid. 
    CREATE TABLE Something_emails 
    (account_id CHAR(15) NOT NULL,
     email_address VARCHAR(256) NOT NULL,
     email_type CHAR(5) NOT NULL
     CHECK (email_type IN ('home', 'work', 'misc')),
     PRIMARY KEY (email_address, email_type)
    >> In this table account_id is unique <<
    No, not without the DDL you did not post.
    >> email values could be NULL or repetitive for work / home / Other (same email can be used more than one columns for account_id) <<
    Not a problem. Look at the primary key.  Also why would anyone store invalid data in a table? SQL programmers try to keep it out! 
    >> a new column will be created with name as Source_flag (the value could be work, Home, Other depend on email coming from) then removes duplicates <<
    More kludges! Oh, putting the comma at the front of a line is how non-SQL mimic punch cards. An SQL progtrqammer would put related subsets of columns on one line – we think in sets! After 30+ years of SQL, this is one of the code smells I use to find bad
    code. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to use this query in R12

    the query below , i am using in valueset :
    select * from AR_LOCATION_VALUES
    Where ar_location_values.location_segment_qualifier =
    'COUNTRY' and ar_location_values.location_structure_id in ( select location_structure_id from ar_system_parameters )
    how to use this query to set in R12?
    Thanks

    hi
    i am using the following query in 11i and i want to use the same in R12 :
    SELECT ar_location_values.location_segment_description,ar_location_values.location_segment_value,location_segment_id
    FROM AR_LOCATION_VALUES
    WHERE ar_location_values.location_segment_qualifier = 'COUNTRY'
    AND ar_location_values.location_structure_id IN
    (SELECT location_structure_id FROM ar_system_parameters)
    note: the table ar_location_values is obsolette in R12 so what is the replacement table in R12 for this?

  • How to modify this query to get the desired output format

    I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
    SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
    FROM ALL_CONS_COLUMNS
    WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
    FROM ALL_CONSTRAINTS AC
    WHERE AC.TABLE_NAME=TABLE_NAME
    AND AC.TABLE_NAME='&TABLE'
    AND AC.R_CONSTRAINT_NAME IS NOT NULL);
    This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
    I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
    For Example I want the output as follows...
    TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
    CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
    EMP DEPTNO DEPT DEPTNO
    In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
    any help on how to tackle would be appreciated.

    Try this query
    SELECT c.table_name child_table,
         c.column_name child_column,
         p.table_name parent_table,
         p.column_name parent_column
    FROM user_constraints a,user_constraints b,user_cons_columns c,
         user_cons_columns p
    WHERE a.r_constraint_name=b.constraint_name and
          a.constraint_name=c.constraint_name and
          b.constraint_name=p.constraint_name and
          c.position=p.position
    ORDER BY c.constraint_name,c.position
    Anwar

  • How to solve this query

    hi,
    i have a product table like
    product month1 month2 month3 .................
    soap 1200 1256 1895 ............
    i want use a query where i can select column name with a parameter.
    like
    select month||:num from product;
    in num variable it cud be 1 to 10 of value that is dependent on my program.
    so how to make this query .
    thxs

    Hi,
    Here is an example that i am helpful.
    In the example , I am using a table 'table_name' which contains columns like
    assign_attribute1
    assign_attribute2
    assign_attribute15
    Now I will pass any number from 1 to 15 to the function.
    create or replace procedure pass_col_number(v_number varchar2) as
    v_sql varchar2(2000);
    v_assign_attribute1   varchar2(150);
    begin
    v_sql := 'select  assign_attribute'||v_number||'  from  table_name where person_id = 1345';
    execute immediate v_sql into v_assign_attribute1;
    dbms_output.put_line('v_assign_attribute1='||v_assign_attribute1);
    end;Edited by: Sreekanth Munagala on Dec 18, 2008 1:18 AM

  • How to combine this query so that i can display the ouput together

    I have no idea how to combine this query together.Someone please help.I want the ouput to display oni 1 result combining all together.
    select facility, route, operation, script_id
    from F_ROUTEOPER
    where facility = 'A01' and operation in ('6910','7976') AND src_erase_date is null
    and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)
    AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
    select facility, route, operation, script_id
    from F_ROUTEOPER
    where facility = 'A01' and operation in ('6912','7976') AND src_erase_date is null
    and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)
    AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
    select facility, route, operation, script_id
    from F_ROUTEOPER
    where facility = 'A01' and operation in ('7344','7976') AND src_erase_date is null
    and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)
    AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
    select facility, route, operation, script_id
    from F_ROUTEOPER
    where facility = 'A01' and operation in ('8344','7976') AND src_erase_date is null
    and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)
    AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
    Edited by: 965547 on Nov 5, 2012 12:55 AM

    The only difference which i am seeing in your queries is the Operation ('6910', '6912','7344','8344')
    Then why don't you put all values in One like this
    Select facility, route, operation, script_id
    from F_ROUTEOPER
    where facility = 'A01' and operation in *('6910', '6912','7344','8344','7976')* AND src_erase_date is null
    and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)
    AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
    Hope this will resolve your problem.
    Oracle-911

  • How to tune this query for the improve performance ?

    Hi All,
    How to tune this query for the improve performance ?
    select a.claim_number,a.pay_cd,a.claim_occurrence_number,
    case
    when sum(case
    when a.payment_status_cd ='0'
    then a.payment_est_amt
    else 0
    end
    )=0
    then 0
    else (sum(case
    when a.payment_status_cd='0'and a.payment_est_amt > 0
    then a.payment_est_amt
    else 0
    end)
    - sum(case
    when a.payment_status_cd<>'0'
    then a.payment_amt
    else 0
    end))
    end as estimate
    from ins_claim_payment a
    where a.as_of_date between '31-jan-03' and '30-aug-06'
    and ( a.data_source = '25' or (a.data_source between '27' and '29'))
    and substr(a.pay_cd,1,1) IN ('2','3','4','8','9')
    group by a.claim_number, a.pay_cd, a.claim_occurrence_number
    Thank you,
    Mcka

    Mcka
    As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
    And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
    Regards Nigel

  • How to write this query to filter combination of few values

    Hi,
    I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
    columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
    HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
    I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
    OR
    if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
    How to write this query?
    Regards

    Hi,
    I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
    CHILD_ID
           3
           4? If so, here's one way to get them:
    WITH     all_vacc_ids     AS
         SELECT     c.child_id
         ,     c.vacc_id          AS child_vacc_id
         ,     v.vacc_id
         ,     COUNT ( CASE
                             WHEN  c.vacc_id = 'HEXA'
                       THEN  1
                         END
                    )       OVER ( PARTITION BY  c.child_id
                                       )    AS hexa_itself
         FROM          vacc   v
         LEFT OUTER JOIN     chimm  c     PARTITION BY (c.child_id)
                          ON     c.vacc_id     = v.vacc_id
         WHERE   v.vacc_desc       = 'HEXA'     -- See note below
    SELECT       child_id
    FROM       all_vacc_ids
    WHERE       child_vacc_id     IS NULL
      AND       vacc_id     != 'HEXA'
      AND       hexa_itself     = 0
    GROUP BY  child_id
    rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
    You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher).

  • How to write this query ?

    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno

    Hi,
    806540 wrote:
    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
    ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno
    If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
    You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
    Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
    If you really, really don't want to use analytic functions at all, you can do this:
    SELECT     *
    FROM     scott.emp
    WHERE     deptno     IN  (
                      SELECT       deptno
                      FROM       scott.emp
                      GROUP BY  deptno
                      HAVING       AVG (sal) =  (
                                                       SELECT    MAX (AVG (sal))
                                               FROM          scott.emp
                                               GROUP BY  deptno
    ;

  • Rewrite this query

    Hi all,
    Can we rewrite this query as simplest.Becasue when i Execute this query it will take more time appro 3hrs.So can we rewrite this as possible.
    SELECT  scon.uabscon_number,
                        scon.uabscon_cust_code,
                        scon.uabscon_prem_code,
                        scon.uabscon_mf_status,
                        letd.usrletd_mf_next_visit_date,
                        evau.ucrevau_invn_code,
                        evau.ucrevau_prod_number
                 FROM   uimsmgr.usrletd letd,
                        uimsmgr.ucrevau evau,
                        uimsmgr.uabscon scon
                 WHERE  scon.uabscon_mf_status = :cMoveForwardPhase
                 AND    scon.uabscon_status_ind IN ('A','R')
                 AND    evau.ucrevau_scon_number = scon.uabscon_number
                 AND    evau.ucrevau_event_type  = :currentLetterTypeLevel /* FLT1,ALT1,FLT2, ... */
                 AND    evau.ucrevau_value_1     = :letterTypeCode /* FV1,ASV1, ... */
                 AND    evau.ucrevau_activity_date = (SELECT max(ee.ucrevau_activity_date)
                                                      FROM   uimsmgr.ucrevau ee
                                                      WHERE  ee.ucrevau_scon_number = scon.uabscon_number
                                                      AND    (ee.ucrevau_event_type like 'FLT%'
                                                              OR ee.ucrevau_event_type like 'ALT%'))
                 AND   letd.usrletd_actual_cust_code  = scon.uabscon_cust_code
                 AND   letd.usrletd_prem_code         = scon.uabscon_prem_code
                 AND   letd.usrletd_letr_code         = :letterTypeCode /* FV1,ASV1, ... */
                 AND   letd.usrletd_printed_date      <= SYSDATE - :mfFirstDelayDays
                 AND   letd.usrletd_printed_ind       = 'Y'
                 AND   TRUNC(letd.usrletd_activity_date) >= TRUNC(evau.ucrevau_activity_date)
                 AND EXISTS (   SELECT 1
                                FROM   uimsmgr.utvsrvc srvc,
                                       uimsmgr.ucrserv serv
                                WHERE  serv.ucrserv_scon_number = scon.uabscon_number
                                AND    serv.ucrserv_cust_code   = scon.uabscon_cust_code
                                AND    serv.ucrserv_prem_code   = scon.uabscon_prem_code
                                AND    TRUNC(serv.ucrserv_next_visit_date) <= TRUNC(SYSDATE) + :mfDueRange
                                AND    serv.ucrserv_srvc_code   = srvc.utvsrvc_code
                                AND    srvc.utvsrvc_bus_sector_id = 1 /* only business sector 1*/
                                AND    DECODE( NVL(serv.ucrserv_next_visit_type, 'A'),
                                                   'NOFV', 'A',
                                                   'FV'  , 'F',
                                                   'FAS' , 'A',
                                                   'A'   , 'A',
                                                           'Z' ) = :visitType
                                );

    SELECT /*+ ordered */  scon.uabscon_number,
                        scon.uabscon_cust_code,
                        scon.uabscon_prem_code,
                        scon.uabscon_mf_status,
                        letd.usrletd_mf_next_visit_date,
                        evau.ucrevau_invn_code,
                        evau.ucrevau_prod_number
                 FROM   uimsmgr.usrletd letd,
                        uimsmgr.ucrevau evau,
                        uimsmgr.uabscon scon
                 WHERE   letd.usrletd_printed_date      <= SYSDATE - :mfFirstDelayDays and scon.uabscon_mf_status = :cMoveForwardPhase
                 AND    scon.uabscon_status_ind IN ('A','R')
                 AND    evau.ucrevau_scon_number = scon.uabscon_number
                 AND    evau.ucrevau_event_type  = :currentLetterTypeLevel /* FLT1,ALT1,FLT2, ... */
                 AND    evau.ucrevau_value_1     = :letterTypeCode /* FV1,ASV1, ... */
                 AND    evau.ucrevau_activity_date = (SELECT max(ee.ucrevau_activity_date)
                                                      FROM   uimsmgr.ucrevau ee
                                                      WHERE  ee.ucrevau_scon_number = scon.uabscon_number
                                                      AND    (ee.ucrevau_event_type like 'FLT%'
                                                              OR ee.ucrevau_event_type like 'ALT%'))
                 AND   letd.usrletd_actual_cust_code  = scon.uabscon_cust_code
                 AND   letd.usrletd_prem_code         = scon.uabscon_prem_code
                 AND   letd.usrletd_letr_code         = :letterTypeCode /* FV1,ASV1, ... */
                 AND   letd.usrletd_printed_ind       = 'Y'
                 AND   TRUNC(letd.usrletd_activity_date) >= TRUNC(evau.ucrevau_activity_date)
                 AND EXISTS (   SELECT 1
                                FROM   uimsmgr.utvsrvc srvc,
                                       uimsmgr.ucrserv serv
                                WHERE  serv.ucrserv_scon_number = scon.uabscon_number
                                AND    serv.ucrserv_cust_code   = scon.uabscon_cust_code
                                AND    serv.ucrserv_prem_code   = scon.uabscon_prem_code
                                AND    TRUNC(serv.ucrserv_next_visit_date) <= TRUNC(SYSDATE) + :mfDueRange
                                AND    serv.ucrserv_srvc_code   = srvc.utvsrvc_code
                                AND    srvc.utvsrvc_bus_sector_id = 1 /* only business sector 1*/
                                AND    DECODE( NVL(serv.ucrserv_next_visit_type, 'A'),
                                                   'NOFV', 'A',
                                                   'FV'  , 'F',
                                                   'FAS' , 'A',
                                                   'A'   , 'A',
                                                           'Z' ) = :visitType
                                )I suggest this admitting on letd.usrletd_printed_date.
    And it would be good if you would also have a lower limit for letd.usrletd_printed_date, so that you would have letd.usrletd_printed_date between ...

  • How can we rewrite this query for better performance

    Hi All,
    The below query is taking more time to run. Any ideas how to improve the performance by rewriting the query using NOT EXITS or any other way...
    Help Appreciated.
    /* Formatted on 2012/04/25 18:00 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    and vendor_id NOT IN ( /* Formatted on 2012/04/25 18:25 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    Thanks

    Try this one :
    This will help you for partial fetching of data
    SELECT /*+ first_rows(50) no_cpu_costing */
    vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    AND vendor_id NOT IN (
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    overall your query is also fine, because, the in this query the subquery always contain less data compare to main query.

  • How to improve this query speed ?....help me

    How to improve the query speed. Any hints can u suggest in the query or any correction. Here i am using sample tables for checking purpose, When i am trying with my original values, this type of query taking longer time to run
    select ename,sal,comm from emp where(comm is null and &status='ok') or (comm is not null and &status='failed');
    Thanx in advance
    prasanth a.s.

    What about
    select ename,sal,comm from emp where comm is null and &status='ok'
    union all
    select ename,sal,comm from emp where comm is not null and &status='failed';
    Regards
    Vaishnavi

  • How to optmize this query

    How can I optimize this query? it's taking a long time to run
    SELECT A.COL1, B.COL2, C.COL3
    FROM A, B, C
    WHERE A.COL1=B.COL2 (+)
    AND B.COL2=C.COL3 (+)
    Thank you!
    H

    ORA-02393: exceeded call limit on CPU usageContact your dba to increase this resource limit in your profile.
    An other way to write your query :
    select a.col1, null, null
    from a
    where not exists (select null from b where A.COL1=B.COL2)
    union
    select a.col1, b.col2, null
    from a,b
    where A.COL1=B.COL2
    and not exists (select null from c where b.COL1=c.COL2)
    union
    select a.col1, b.col2, c.col3
    from a,b, c
    where A.COL1=B.COL2
    and B.COL2=C.COL3;[pre]
    Nicolas.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is there any way to rewrite this query?

    Is there room for improvement/rewrite for this query so that it performs well?
    select distinct shp_locn
      from shp_mstr
    where zone = to_char(:b3)
       and locn_class = 'r'
       and aisle = 'GX-08'
       and dock =  'KN'
       and locn_id not in (select locn_id from tmp_shp_out_dtl)
    order by shp_locn

    user659394 wrote:
    Alex,
    Stop your st_u_pi_d f_u_c__king sarcasm. There were lots of instances like the below thread
    where you bring your boring sarcasm to meaningful technical discussions.
    If you dont want to answer, just leave it..... you C__u__n__t
    Error for a SELECT COUNT ... in stored proc
    Alex was giving you perfectly valid assistance.
    Your post has now been reported to the moderators as it is completely offensive, unprofessional and unnecessary.

Maybe you are looking for