Help on the query

Hi all,
I am trying to fetch a value from table 1 if there is no record on that table , then i need to select from table 2
Can we do this in a single query without using exception or cursors

Under Forum Home - Database: PL/SQL
K.

Similar Messages

  • Help wit the query

    I need help with the query
    Here is what I need
    For a particular comm record if there is no Salary record where comm:Date = Salary:Date, then
    • Find maximum dated Salary record as of comm:Date.
    • Clone this record and set Salary:Date = comm:Date
    • Set Salary:rate = comm:rate
    Like wise for a particular Salary record If there is no comm record where Salary:Date = comm:Date then
    • Find maximum effective dated comm record as of Salary:Date
    • Apply Rate 2 amount from this maximum effective dated record to Salary record i.e. Set Salary:rate = comm:rate
    Example
    Salary Table :
    ID Sal_Date Rate Hours
    1 07/01/2011 400.00 40
    2 02/15/2011 200.00 40
    3 01/01/2011 160.00 40
    Sal_comm Table:
    Sal_Date comm_Rate
    1 07/01/2011 10.00
    4 03/01/2011 7.50
    3 01/01/2011 4.00
    I need to merge comm_Rate column in Salary table, since there is no salary record as off 03/01/2011, I need to find the maximum dated salary record as of 03/01/2011
    i.e. the record dated 02/15/2011. Now I need to clone that salary record, set the SAL_date as 03/01/2011 and update Rate2 amount. So the record set will be like:
    Sal_Date:
    id sal_Date Rate Hours comm_Rate
    1 07/01/2011 400.00 40 10.00
    4 03/01/2011 200.00 40 7.50
    2 02/15/2011 200.00 40 4.00
    3 01/01/2011 160.00 40 4.00

    So you need all used dates as the "driving" dataset. And you need the according data for each of these.
    WITH salary_table as
    (select 1 id,to_date('07/01/2011','MM/DD/YYYY')sal_date,400 rate,40 hours from dual union all
    select 2 id,to_date('02/15/2011','MM/DD/YYYY')sal_date,200 rate,40 hours from dual union all
    select 3 id,to_date('01/01/2011','MM/DD/YYYY')sal_date,160 rate,40 hours from dual),
    sal_comm as
    (select 1 id,to_date('07/01/2011','MM/DD/YYYY')sal_date,10 comm_Rate from dual union all
    select 4 id,to_date('03/01/2011','MM/DD/YYYY')sal_date,7.5 comm_Rate from dual union all
    select 3 id,to_date('01/01/2011','MM/DD/YYYY')sal_date,4 comm_Rate from dual)
    select to_char(all_dates.sal_date,'MM/DD/YYYY') sal_date,sal.rate,sal.hours,com.comm_rate
    from (select sal_date from salary_table
          union
          select sal_date from sal_comm) all_dates
    inner join (select s1.*,lead(sal_date-1,1,to_date('31/12/9999','DD/MM/YYYY')) over (order by sal_date) next_sal_date
               from salary_table s1) sal
      on (all_dates.sal_date between sal.sal_date and sal.next_sal_date)
    inner join (select s1.*,lead(sal_date-1,1,to_date('31/12/9999','DD/MM/YYYY')) over (order by sal_date) next_sal_date
               from sal_comm s1) com
      on (all_dates.sal_date between com.sal_date and com.next_sal_date)
    order by   all_dates.sal_date desc;
    SAL_DATE   RATE                   HOURS                  COMM_RATE             
    07/01/2011 400                    40                     10                    
    03/01/2011 200                    40                     7.5                   
    02/15/2011 200                    40                     4                     
    01/01/2011 160                    40                     4                     
         

  • Please Help for the Query

    Please Help for the Query
    Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/18/2008 3IINFOTECH -4
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    as such :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
    In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
    So I want the data
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3

    SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
    Tabla creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
    1 fila creada.
    SQL> COMMIT;
    Validación terminada.
    SQL>
    SQL> SELECT FECHA, INDICA
      2  FROM BORRAME
      3  WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
      4  ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
    FECHA                                                                
    INDICA                                                               
    13/03/08                                                             
    3IINFOTECH -8                                                        
    25/03/08                                                             
    3IINFOTECH -5                                                        
    27/03/08                                                             
    3IINFOTECH -3                                                        
                    

  • A filter to be applied on the F4 help in the query

    Hi
    I have a requirement wherein the user wants a filter to be applied on the F4 help in the query (for e.g. company code) for a specific area(for this e.g. real estate). Can I do this as now it brings all the company codes that exist
    Thanks
    Bhima

    Hi,
    It might be done. If your specific area is a compounding attribute to company code then restrict your area and co_code by variables (user entry). After you enter area into variable, F4 help for a co_code variable will show only codes from the entered area.
    Best regards,
    Eugene

  • Infoobject F4 help in the Query takes lot of time and hangs

    Hi All,
    I have 0Material in the query and the F4 help  for selection takes lot of time and hangs after some time.
    The 0Material has 2 million records the  Infoobject properties for Bex are as below:
    Selection:No selection restriction
    Query Def. Filter Value Selection: Values in Master Data Table
    Query Execution Filter Val.Selectn:Only Posted Values for Navigation
    We tried to alter some of the Properties but we have the same issue.
    Suggest other options that can be be looked into to get the F4 help in the Query .
    Thanks,
    Mike

    hi Mike,
    check if helps
    Note 817335 - Performance in F4 Help 
    Note 748623 - Input help (F4) has a very long runtime - recommendations
    Note 581802 - Variable dialog boxes: performance of the F4 help
    search oss note for f4 performance ......

  • Help in the query

    hi folks,
    Help me to build the query here.
    Tables BKPF - fields belnr, blart
           BSEG - fields kunnr,wrbtr, zuonr
    I need to get the data into a single internal table whose strucutre consists of fields kunnr, blart,wrbtr and zuonr
    the common field between the two tables is belnr and the query should be run based on 'zuonr' field
    i.e
    select ......................... where bseg-zuonr = p_advnum(paramter field where I get the data)
    Question how to establish relation between two tables in asingle query without the use of 'JOIN' statements because BSEG is a cluster table and i cannot do that.
    Thanks in advance.
    Santhosh

    Here's one way, but that hit to BSEG may take a while if you don't have an index for that field.
    data: xbkpf type bkpf.
    data: ibseg type table of bkpf with header line.
    data: begin of itab occurs 0,
          kunnr type bseg-kunnr,
          blart type bkpf-blart,
          wrbtr type bseg-wrbtr,
          zuonr type bseg-zuonr,
          end of itab.
    parameters: p_advnum type bseg-zuonr.
    select * into corresponding fields of table ibseg
             from bseg
                 where zuonr = p_advnum.
    loop at ibseg.
      move-corresponding ibseg to itab.
      clear xbkpf.
      select single * from bkpf into xbkpf
              where belnr = ibseg-belnr.
      itab-blart = ibseg-blart.
      append itab.
    endloop.
    Regards,
    Rich Heilman

  • Please help rewrite the query

    Hi ,
    Below query is taking more time (4mins) for 41 rows returning and there is no full table scan .Can some one help to rewrite the query.
    SELECT
              esma.candidate AS candidate_additional_sample,
              ccr.raw_mark,
              ccr.split_session_year AS year,
              ccr.split_session_month AS month,
              ccr.paper_code,
              ccr.assessment_school AS school_code,
              get_cand_session_number(ccr.split_session_year,ccr.split_session_month,ccr.candidate) AS candidate_session_number,
              ccr.candidate AS candidate_code,
              c.firstname AS candidate_firstname,
              c.lastname AS candidate_lastname,
              ema.moderator_code,
              ema.examiner_code,
              csr.self_taught
             FROM
              ibis.candidate_component_reg ccr
            INNER JOIN ibis.candidate_examiner_allocation cea
               ON ccr.split_session_year= cea.year
              AND ccr.split_session_month=cea.month
              AND ccr.assessment_school=cea.assessment_school
              AND ccr.paper_code= cea.paper_code
              AND ccr.candidate     =        cea.candidate
            INNER JOIN ibis.examination_paper ep
              ON ccr.split_session_year= ep.year
              AND ccr.split_session_month=ep.month
              AND ccr.paper_code=ep.paper_code
            INNER JOIN ibis.examiner_moderator_allocation ema
              ON ema.year =cea.year
              AND ema.month =cea.month
              AND ema.no_lang_code=ep.no_lang_code
              AND ema.examiner_code=cea.examiner_code
              AND ema.year =ccr.split_session_year
              AND ema.month =ccr.split_session_month
            INNER JOIN ibis.candidate_subject_registration csr
              ON ccr.split_session_year=csr.year
              AND ccr.split_session_month=csr.month
              AND ccr.main_school=csr.main_school
              AND ccr.candidate=csr.candidate
              AND ccr.subject=csr.subject
              AND ccr.subject_option=csr.subject_option
              AND ccr.lvl=csr.lvl
              AND ccr.language=csr.language 
            INNER JOIN ibis.candidate c
              ON ccr.candidate=c.candidate
            LEFT OUTER JOIN  ibis.exam_sample_mark_additional esma
              ON ccr.split_session_year = esma.year
              AND ccr.split_session_month  = esma.month
              AND ep.no_lang_code = esma.nolang_code
              AND ccr.candidate = esma.candidate
            WHERE
                  ccr.split_session_year=:v_year
              AND ccr.split_session_month=:v_month
              AND ccr.subject=:v_subject
              AND ccr.subject_option=nvl(:v_subject_option,ccr.subject_option)
              AND ccr.language=nvl(:v_language, ccr.language)
              AND ccr.component=:v_component
              AND ccr.lvl=:v_lvl
              AND ccr.raw_mark IS NOT NULL          
              AND cea.examiner_code  = :v_examiner_code
              AND ((ccr.sampled='Y'
                      AND csr.self_taught='N'
                      AND EXISTS (SELECT 1 FROM ibis.subject_component sc
                                  WHERE sc.assessment_method_id = 11
                                    AND sc.assessment_type='INTERNAL'
                                    AND ccr.split_session_year=sc.year
                                    AND ccr.split_session_month=sc.month
                                    AND ccr.paper_code=sc.paper_code
                                    AND ccr.subject=sc.subject
                                    AND ccr.subject_option=sc.subject_option
                                    AND ccr.lvl=sc.lvl
                                    AND ccr.language=sc.language
                                    AND ccr.component=sc.component)
                      AND NOT EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
                                      WHERE ccr.split_session_year = cpt.year
                                        AND ccr.split_session_month = cpt.month
                                        AND ccr.subject = cpt.subject
                                        AND ccr.subject_option = cpt.subject_option
                                        AND ccr.component = cpt.component
                                        AND cpt.combined = 'Y')
                      AND NOT EXISTS (SELECT 1 FROM ibis.school_sample_mark ssm
                                      WHERE ssm.year= ccr.split_session_year
                                        AND ssm.month  = ccr.split_session_month
                                        AND ssm.paper_code  = ccr.paper_code
                                        AND ssm.candidate =ccr.candidate
                                        AND ssm.examiner_sample = 'Y'))
                  OR (ccr.sampled='N'
                      AND csr.self_taught='Y'
                      AND EXISTS (SELECT 1 FROM ibis.subject_component sc
                                  WHERE sc.assessment_method_id = 11
                                    AND ccr.split_session_year=sc.year
                                    AND ccr.split_session_month=sc.month
                                    AND ccr.paper_code=sc.paper_code
                                    AND ccr.subject=sc.subject
                                    AND ccr.subject_option=sc.subject_option
                                    AND ccr.lvl=sc.lvl
                                    AND ccr.language=sc.language
                                    AND ccr.component=sc.component)
                      AND NOT EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
                                      WHERE ccr.split_session_year = cpt.year
                                        AND ccr.split_session_month = cpt.month
                                        AND ccr.subject = cpt.subject
                                        AND ccr.subject_option = cpt.subject_option
                                        AND ccr.component = cpt.component
                                        AND cpt.combined = 'Y'))
                  OR (ccr.sampled='N'
                      AND EXISTS (SELECT 1 FROM ibis.subject_component sc
                                  WHERE sc.assessment_method_id = 11
                                    AND ccr.split_session_year=sc.year
                                    AND ccr.split_session_month=sc.month
                                    AND ccr.paper_code=sc.paper_code
                                    AND ccr.subject=sc.subject
                                    AND ccr.subject_option=sc.subject_option
                                    AND ccr.lvl=sc.lvl
                                    AND ccr.language=sc.language
                                    AND ccr.component=sc.component)
                      AND EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
                                      WHERE ccr.split_session_year = cpt.year
                                        AND ccr.split_session_month = cpt.month
                                        AND ccr.subject = cpt.subject
                                        AND ccr.subject_option = cpt.subject_option
                                        AND ccr.component = cpt.component
                                        AND cpt.combined = 'Y')));
    explain plan
    line 1: SQLPLUS Command Skipped: set linesize 130
    line 2: SQLPLUS Command Skipped: set pagesize 0
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 2594643366                                                                                                                                                                                                                                                                                 
    | Id  | Operation                             | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                    
    |   0 | SELECT STATEMENT                      |                                |     2 |  1036 |    34   (3)| 00:00:01 |                                                                                                                                                                                    
    |*  1 |  FILTER                               |                                |       |       |            |          |                                                                                                                                                                                    
    |*  2 |   HASH JOIN OUTER                     |                                |     2 |  1036 |    34   (3)| 00:00:01 |                                                                                                                                                                                    
    |   3 |    VIEW                               |                                |     2 |   974 |    32   (0)| 00:00:01 |                                                                                                                                                                                    
    |   4 |     CONCATENATION                     |                                |       |       |            |          |                                                                                                                                                                                    
    |*  5 |      FILTER                           |                                |       |       |            |          |                                                                                                                                                                                    
    |*  6 |       TABLE ACCESS BY INDEX ROWID     | CANDIDATE_SUBJECT_REGISTRATION |     1 |    58 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |   7 |        NESTED LOOPS                   |                                |     1 |   485 |    16   (0)| 00:00:01 |                                                                                                                                                                                    
    |   8 |         NESTED LOOPS                  |                                |     1 |   427 |    13   (0)| 00:00:01 |                                                                                                                                                                                    
    |   9 |          NESTED LOOPS                 |                                |     1 |   357 |    11   (0)| 00:00:01 |                                                                                                                                                                                    
    |  10 |           NESTED LOOPS                |                                |     1 |   129 |     8   (0)| 00:00:01 |                                                                                                                                                                                    
    |  11 |            NESTED LOOPS               |                                |     1 |    80 |     5   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 12 |             INDEX RANGE SCAN          | PK_EXAMINER_MODERATOR_ALLOC    |     1 |    39 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 13 |             INDEX RANGE SCAN          | RFL_EP1                        |     1 |    41 |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |  14 |            TABLE ACCESS BY INDEX ROWID| CANDIDATE_EXAMINER_ALLOCATION  |     1 |    49 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 15 |             INDEX RANGE SCAN          | CANDIDATE_ALLOCATION_EXAMINER  |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 16 |           TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG        |     1 |   228 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 17 |            INDEX RANGE SCAN           | SPLIT_SESSION_CANDIDATE        |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |  18 |          TABLE ACCESS BY INDEX ROWID  | CANDIDATE                      |     1 |    70 |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 19 |           INDEX UNIQUE SCAN           | CANDIDATE_PK                   |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 20 |         INDEX RANGE SCAN              | Y_M_CAND_SUBJ_LVL_OPTION       |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 21 |      FILTER                           |                                |       |       |            |          |                                                                                                                                                                                    
    |* 22 |       TABLE ACCESS BY INDEX ROWID     | CANDIDATE_SUBJECT_REGISTRATION |     1 |    58 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |  23 |        NESTED LOOPS                   |                                |     1 |   485 |    16   (0)| 00:00:01 |                                                                                                                                                                                    
    |  24 |         NESTED LOOPS                  |                                |     1 |   427 |    13   (0)| 00:00:01 |                                                                                                                                                                                    
    |  25 |          NESTED LOOPS                 |                                |     1 |   357 |    11   (0)| 00:00:01 |                                                                                                                                                                                    
    |  26 |           NESTED LOOPS                |                                |     1 |   129 |     8   (0)| 00:00:01 |                                                                                                                                                                                    
    |  27 |            NESTED LOOPS               |                                |     1 |    80 |     5   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 28 |             INDEX RANGE SCAN          | PK_EXAMINER_MODERATOR_ALLOC    |     1 |    39 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 29 |             INDEX RANGE SCAN          | RFL_EP1                        |     1 |    41 |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |  30 |            TABLE ACCESS BY INDEX ROWID| CANDIDATE_EXAMINER_ALLOCATION  |     1 |    49 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 31 |             INDEX RANGE SCAN          | CANDIDATE_ALLOCATION_EXAMINER  |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 32 |           TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG        |     1 |   228 |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 33 |            INDEX RANGE SCAN           | SPLIT_SESSION_CANDIDATE        |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |  34 |          TABLE ACCESS BY INDEX ROWID  | CANDIDATE                      |     1 |    70 |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 35 |           INDEX UNIQUE SCAN           | CANDIDATE_PK                   |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 36 |         INDEX RANGE SCAN              | Y_M_CAND_SUBJ_LVL_OPTION       |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 37 |    INDEX RANGE SCAN                   | EXAM_SAMP_MARK_ADD_IOT_PK      |    36 |  1116 |     1   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 38 |   TABLE ACCESS BY INDEX ROWID         | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 39 |    INDEX RANGE SCAN                   | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 40 |    TABLE ACCESS BY INDEX ROWID        | SCHOOL_SAMPLE_MARK             |     1 |    34 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 41 |     INDEX RANGE SCAN                  | CAND_PAPER_YEAR_MONTH          |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 42 |     TABLE ACCESS BY INDEX ROWID       | SUBJECT_COMPONENT              |     1 |    96 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 43 |      INDEX RANGE SCAN                 | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 44 |      TABLE ACCESS BY INDEX ROWID      | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 45 |       INDEX RANGE SCAN                | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 46 |       TABLE ACCESS BY INDEX ROWID     | SUBJECT_COMPONENT              |     1 |    87 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 47 |        INDEX RANGE SCAN               | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 48 |        TABLE ACCESS BY INDEX ROWID    | SUBJECT_COMPONENT              |     1 |    87 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 49 |         INDEX RANGE SCAN              | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 50 |         TABLE ACCESS BY INDEX ROWID   | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                                    
    |* 51 |          INDEX RANGE SCAN             | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                                    
      Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter("from$_subquery$_011"."SAMPLED"='Y' AND "from$_subquery$_011"."SELF_TAUGHT"='N' AND  NOT EXISTS                                                                                                                                                                                               
                  (SELECT /*+ */ 0 FROM "IBIS"."CW_PORTFOLIO_TEMPLATE" "CPT" WHERE "CPT"."COMPONENT"=:B1 AND                                                                                                                                                                                                    
                  "CPT"."SUBJECT_OPTION"=:B2 AND "CPT"."SUBJECT"=:B3 AND "CPT"."MONTH"=:B4 AND "CPT"."YEAR"=:B5 AND                                                                                                                                                                                             
                  "CPT"."COMBINED"='Y') AND  NOT EXISTS (SELECT /*+ */ 0 FROM "IBIS"."SCHOOL_SAMPLE_MARK" "SSM" WHERE                                                                                                                                                                                           
                  "SSM"."MONTH"=:B6 AND "SSM"."YEAR"=:B7 AND "SSM"."PAPER_CODE"=:B8 AND "SSM"."CANDIDATE"=:B9 AND                                                                                                                                                                                               
                  "SSM"."EXAMINER_SAMPLE"='Y') AND  EXISTS (SELECT /*+ */ 0 FROM "IBIS"."SUBJECT_COMPONENT" "SC" WHERE                                                                                                                                                                                          
                  "SC"."COMPONENT"=:B10 AND "SC"."SUBJECT_OPTION"=:B11 AND "SC"."LANGUAGE"=:B12 AND "SC"."LVL"=:B13 AND                                                                                                                                                                                         
                  "SC"."SUBJECT"=:B14 AND "SC"."MONTH"=:B15 AND "SC"."YEAR"=:B16 AND "SC"."PAPER_CODE"=:B17 AND                                                                                                                                                                                                 
                  "SC"."ASSESSMENT_METHOD_ID"=11 AND "SC"."ASSESSMENT_TYPE"='INTERNAL') OR "from$_subquery$_011"."SAMPLED"='N'                                                                                                                                                                                  
                  AND "from$_subquery$_011"."SELF_TAUGHT"='Y' AND  NOT EXISTS (SELECT /*+ */ 0 FROM                                                                                                                                                                                                             
                  "IBIS"."CW_PORTFOLIO_TEMPLATE" "CPT" WHERE "CPT"."COMPONENT"=:B18 AND "CPT"."SUBJECT_OPTION"=:B19 AND                                                                                                                                                                                         
                  "CPT"."SUBJECT"=:B20 AND "CPT"."MONTH"=:B21 AND "CPT"."YEAR"=:B22 AND "CPT"."COMBINED"='Y') AND  EXISTS (SELECT                                                                                                                                                                               
                  /*+ */ 0 FROM "IBIS"."SUBJECT_COMPONENT" "SC" WHERE "SC"."COMPONENT"=:B23 AND "SC"."SUBJECT_OPTION"=:B24 ANDEdited by

    Can you please post the following scripts:
    1. Tables structure (with all indexes & constraints)
    2. Tables data
    3. SQL trace file
    possibly everything that one can need to regenerate the scenario on his own DB...
    OR
    spend some time with Oracle Docs on Performance Tuning and then resolve it yourself.
    Regards,
    Ankit Rathi
    http://theoraclelog.blogspot.in

  • Need urgent help with the query - Beginer

    Hello - I need help with a query to populate data in a table.Here is the scenario.
    Source1
    MnthID BranchCod CustID SegCode FXStatus ProfStatus Profit
    200712 B1 C1 20 Y Y 100
    Source2
    MnthID BranchCod CustID ProdCode ProdIndex
    200712 B1 C1 12 1
    200712 B1 C2 12 0
    Destination
    MnthID BranchCod SegCode ProdCode CountSegCust CountProdCust ProfitProdCust
    Condition and Calculations:
    1)Source1 customer are base customers.If Source2 has customers who is not in source1 then that customer's record should not be fetched.
    2)SegCode, FX Status, ProfStatus is one variable in destination table. [ SegCode = SegCode+ FXStatus (if FXStatus = Y)+ ProfStatus (if FXStatus = Y) ]
    3)CountSegCust = CountCustID Groupby MnthID,BranchCod,SegCode Only.
    4)CountProdCust = CountCustID Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
    5)ProfitProdCust = Sum of Profit of Customers Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
    Apologies for bad formatting.
    Thanks in advance!!

    A total guess indeed.
    It's not clear whether some aggregation can be done (summing counts of grouped data might cause some customers being counted more than once)
    insert into destination
    select mnthid,branchcod,segcode,prodcode,countsegcust,countprodcust,profitprodcust
      from (select s1.mnthid,
                   s1.branchcod,
                   s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end segcode,
                   s2.prodcode,
                   count(s1.custid) over (partition by s1.mnthid,
                                                       s1.branchcod,
                                                       s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                              order by null
                                         ) countsegcust,
                   count(case proindex when 1
                                       then custid
                         end
                        ) over (partition by s1.mnthid,
                                             s1.branchcod,
                                             s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                             s2.prodcode
                                    order by null
                               ) countprodcust,
                   sum(case proindex when 1
                                     then profit
                       end
                      ) over (partition by s1.mnthid,
                                           s1.branchcod,
                                           s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                           s2.prodcode
                                  order by null
                             ) profitprodcust,
                   row_number() over (partition by s1.mnthid,
                                                   s1.branchcod,
                                                   s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
                                                   s2.prodcode
                                          order by null
                                     ) the_row
              from source1 s1,source2 s2
             where s1.mnthid = s2.mnthid
               and s1.branchcod = s2.branchcod
               and s1.custid = s2.custid
    where the_row = 1Regards
    Etbin

  • Help for the query

    hello,
    I have a question again. The tables for the query are "Patient" and "Station".
    Station-Table:
    s_id, station
    Patient-Table:
    p_id, name, s_id, gender
    I want to know how many Patient are Male and Female for each Station. That means that the output should be:
    Station Male Female
    S1 12 10
    S2 6 4

    I supposed the values in gender are 'M' for Male and 'F' for Female
    select s.station, sum(decode(p.gender, 'M', 1, 0)) Male , sum(decode(p.gender, 'F', 1, 0)) Female
    from station s, patient p
    where s.s_id=p.s_id
    group by s.station;

  • Please help with the query creating Materialized View

    Hi,
    We are using the below query to create a Materialized View but it has been running since 3 hours. It is an Oracle 9i database running in HP-UX.The quey is as follows,
    (SELECT
    /*+ use_nl(A) parallel (A,4)*/
    A.ICD_CODE AS ICD_CODE,
    A.ICD_DESC AS ICD_DESC,
    A.PROC_GROUP as PROC_GROUP,
    B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
    B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
    C.PROC_TYPE AS PROC_TYPE ,
    C.I_O_IND AS I_O_IND,
    C.DISC_MON AS QUARTER ,
    B.PAT_KEY AS PAT_KEY ,
    D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
    C.PROV_ID AS PROV_ID ,
    A.SPECIALTY AS SPECIALTY
    FROM
    EES_ICD_9_CODE A ,
    EES_CLINICAL_COMPL_DATA B,
    EES_CLINICAL_DATA C,
    EES_CLINCL_COMPL_ICD D                                                                            
    WHERE A.ICD_CODE= B.ICD_CODE
                    AND B.ICD_CODE= C.ICD_CODE
                    AND B.COMPL_ICD_CODE=D.ICD_9_CD
                    AND B.PAT_KEY=C.PAT_KEY
                    AND B.COMPL_ICD_CODEB.ICD_CODE
                    AND C.PROC_TYPE  'L'
                    AND B.COMPL_GRP_TXT'Reoperations'
                    AND D.COMPL_TYPE_TXT'Intra-operative Misadventure'
                    AND C.DISC_MON>='2003101'
                    AND A.SPECIALTY='Colo-Rectal')
    union
    (SELECT
    /*+ use_nl(A) parallel (A,4)*/
    A.ICD_CODE AS ICD_CODE,
    A.ICD_DESC AS ICD_DESC,
    A.PROC_GROUP as PROC_GROUP,
    B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
    B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
    C.PROC_TYPE AS PROC_TYPE ,
    C.I_O_IND AS I_O_IND,
    C.DISC_MON AS QUARTER ,
    B.PAT_KEY AS PAT_KEY ,
    D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
    C.PROV_ID AS PROV_ID ,
    A.SPECIALTY AS SPECIALTY
    FROM
    EES_ICD_9_CODE A ,
    EES_CLINICAL_COMPL_DATA B,
    EES_CLINICAL_DATA C,
    EES_CLINCL_COMPL_ICD D                                                                            
    WHERE A.ICD_CODE= B.ICD_CODE
                    AND B.ICD_CODE= C.ICD_CODE
                    AND B.COMPL_ICD_CODE=D.ICD_9_CD
                   AND B.PAT_KEY=C.PAT_KEY
                    AND B.COMPL_ICD_CODEB.ICD_CODE
                    AND C.PROC_TYPE  'L'
                    --AND B.COMPL_GRP_TXT'Reoperations'
                    AND D.COMPL_TYPE_TXT='Intra-operative Misadventure'
                    AND B.PROC_DAY=C.PROC_DAY
                    AND C.DISC_MON>='2003101'
                    AND A.SPECIALTY='Colo-Rectal')
    union
    (SELECT
    /*+ use_nl(A) parallel (A,4)*/
    A.ICD_CODE AS ICD_CODE,
    A.ICD_DESC AS ICD_DESC,
    A.PROC_GROUP as PROC_GROUP,
    B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
    B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
    C.PROC_TYPE AS PROC_TYPE ,
    C.I_O_IND AS I_O_IND,
    C.DISC_MON AS QUARTER ,
    B.PAT_KEY AS PAT_KEY ,
    D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
    C.PROV_ID AS PROV_ID ,
    A.SPECIALTY AS SPECIALTY
    FROM
    EES_ICD_9_CODE A ,
    EES_CLINICAL_COMPL_DATA B,
    EES_CLINICAL_DATA C,
    EES_CLINCL_COMPL_ICD D                                                                            
    WHERE A.ICD_CODE= B.ICD_CODE
                    AND B.ICD_CODE= C.ICD_CODE
                    AND B.COMPL_ICD_CODE=D.ICD_9_CD
                    AND B.PAT_KEY=C.PAT_KEY
                    AND B.COMPL_ICD_CODEB.ICD_CODE
                    AND C.PROC_TYPE  'L'
                    AND B.COMPL_GRP_TXT='Reoperations'
                    --AND D.COMPL_TYPE_TXT='Intra-operative Misadventure'
                    AND B.PROC_DAY>C.PROC_DAY
                    AND C.DISC_MON>='2003101'
                    AND A.SPECIALTY='Colo-Rectal')
    The explain plan is as follows,
    PLAN_TABLE_OUTPUT
    | Id  | Operation                          |  Name                    | Rows  | Bytes |TempSpc| Cost  |  TQ    |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT                   |                          | 46935 |  6716K|       | 10648 |        |      |            |
    |   1 |  SORT UNIQUE                       |                          | 46935 |  6716K|    14M| 10648 | 45,14  | P->S | QC (RAND)  |
    |   2 |   UNION-ALL                        |                          |       |       |       |       | 45,13  | P->P | HASH       |
    |*  3 |    HASH JOIN                       |                          | 42801 |  6102K|       |  4640 | 45,13  | PCWP |            |
    |*  4 |     TABLE ACCESS FULL              | EES_CLINCL_COMPL_ICD     |   875 | 18375 |       |     2 | 45,02
    |*  5 |     HASH JOIN                      |                          | 41552 |  5072K|    14M|  4638 | 45,13  | PCWP |            |
    |*  6 |      TABLE ACCESS FULL             | EES_CLINICAL_DATA        |  1430K|    40M|       |  2855 | 45,03
    |*  7 |      HASH JOIN                     |                          |   628K|    56M|       |   494 | 45,10  | P->P | HASH       |
    |*  8 |       TABLE ACCESS FULL            | EES_ICD_9_CODE           |    37 |  2183 |       |     1 | 45,08 
    |*  9 |       TABLE ACCESS BY INDEX ROWID  | EES_CLINICAL_COMPL_DATA  |  2090K|    71M|       |   49
    |  10 |        BITMAP CONVERSION TO ROWIDS |                          |       |       |       |       |        |    
    |* 11 |         BITMAP INDEX FULL SCAN     | INX_COMPL_GRP            |       |       |       |       |        |
    |* 12 |    TABLE ACCESS BY INDEX ROWID     | EES_CLINICAL_DATA        |     1 |    33 |       |     1
    |  13 |     NESTED LOOPS                   |                          |  1327 |   196K|       |   947 | 45,13  | PCWP |            |
    |* 14 |      HASH JOIN                     |                          | 60205 |  6996K|       |   495 | 45,13  | PCWP |            |
    |  15 |       TABLE ACCESS BY INDEX ROWID  | EES_CLINCL_COMPL_ICD     |    36 |   756 |       |    
    |* 16 |        INDEX RANGE SCAN            | COMPL_TYPE_TXT_3         |     1 |       |       |     1 |     
    |* 17 |       HASH JOIN                    |                          |  1420K|   132M|       |   494 | 45,13  | PCWP |            |
    |* 18 |        TABLE ACCESS FULL           | EES_ICD_9_CODE           |    37 |  2183 |       |     1 | 45,11 
    |* 19 |        TABLE ACCESS BY INDEX ROWID | EES_CLINICAL_COMPL_DATA  |  4722K|   175M|       |   49
    |  20 |         BITMAP CONVERSION TO ROWIDS|                          |       |       |       |       |        |      |           
    |  21 |          BITMAP INDEX FULL SCAN    | INX_COMPL_GRP            |       |       |       |       |        |
    |* 22 |      INDEX RANGE SCAN              | EES_CLINICAL_DATA_IND1   |     1 |       |       |     2 | 45,13
    |* 23 |    HASH JOIN                       |                          |  2807 |   416K|       |  4695 | 45,13  | PCWP |            |
    |  24 |     TABLE ACCESS FULL              | EES_CLINCL_COMPL_ICD     |   911 | 19131 |       |     2 | 45,06
    |* 25 |     HASH JOIN                      |                          |  2617 |   334K|    15M|  4693 | 45,13  | PCWP |            |
    |* 26 |      TABLE ACCESS FULL             | EES_CLINICAL_DATA        |  1430K|    45M|       |  2855 | 45,07
    |* 27 |      HASH JOIN                     |                          |   791K|    74M|       |   305 | 45,12  | P->P | HASH       |
    |* 28 |       TABLE ACCESS FULL            | EES_ICD_9_CODE           |    37 |  2183 |       |     1 | 45,09 
    |* 29 |       TABLE ACCESS BY INDEX ROWID  | EES_CLINICAL_COMPL_DATA  |  2632K|    97M|       |   30
    |  30 |        BITMAP CONVERSION TO ROWIDS |                          |       |       |       |       |        |    
    |* 31 |         BITMAP INDEX SINGLE VALUE  | INX_COMPL_GRP            |       |       |       |       |        |
    Predicate Information (identified by operation id):
       3 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
       4 - filter("D"."COMPL_TYPE_TXT"'Intra-operative Misadventure')
       5 - access("B"."ICD_CODE"="C"."ICD_CODE" AND "B"."PAT_KEY"="C"."PAT_KEY")
       6 - filter("C"."PROC_TYPE"'L' AND "C"."DISC_MON">=2003101)
       7 - access("A"."ICD_CODE"="B"."ICD_CODE")
       8 - filter("A"."SPECIALTY"='Colo-Rectal')
       9 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
      11 - filter("B"."COMPL_GRP_TXT"'Reoperations')
      12 - filter("B"."ICD_CODE"="C"."ICD_CODE" AND "C"."PROC_TYPE"'L' AND "B"."PROC_DAY"="C"."PROC_DA
      14 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
      16 - access("D"."COMPL_TYPE_TXT"='Intra-operative Misadventure')
      17 - access("A"."ICD_CODE"="B"."ICD_CODE")
      18 - filter("A"."SPECIALTY"='Colo-Rectal')
      19 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
      22 - access("B"."PAT_KEY"="C"."PAT_KEY")
      23 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
      25 - access("B"."ICD_CODE"="C"."ICD_CODE" AND "B"."PAT_KEY"="C"."PAT_KEY")
           filter("B"."PROC_DAY">"C"."PROC_DAY")
      26 - filter("C"."PROC_TYPE"'L' AND "C"."DISC_MON">=2003101)
      27 - access("A"."ICD_CODE"="B"."ICD_CODE")
      28 - filter("A"."SPECIALTY"='Colo-Rectal')
      29 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
      31 - access("B"."COMPL_GRP_TXT"='Reoperations')
    Note: cpu costing is offPlease help.

    Try removing the hints.
    Is 47,000 a reasonable estimate of how many rows you expect in the results?
    See these posts for other information that you should supply.
    HOW TO: Post a SQL statement tuning request
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long
    When your query takes too long ...

  • Help in the query for sub total.

    hi friends.
           i have a query display below output.
          but i wanted to get sub total of each repeated records,.
    Output is like below.  
    Segment
    Units
    Total items
    CRE
    CRE - MUMBAI
    3
    CTA
    CTA - CHENNAI
    13
    CTA
    CTA - DELHI
    37
    CTA
    CTA - HYDERABAD
    10
    CTA
    CTA - KOLKATTA
    22
    CTA
    CTA - MUMBAI
    110
    Now i need to show like below.  if you see the sub total in bold.
    Segment
    Units
    Total items
    CRE
    CRE - MUMBAI
    3
    CRE
    Sub Total
    3
    CTA
    CTA - CHENNAI
    13
    CTA
    CTA - DELHI
    37
    CTA
    CTA - HYDERABAD
    10
    CTA
    CTA - KOLKATTA
    22
    CTA
    CTA - MUMBAI
    110
    CTA
    Sub Total
    192
    please help.

    with
    the_data as
    (select 'CRE' segment,'CRE - MUMBAI' units,3 total_items from dual union all
    select 'CTA','CTA - CHENNAI',13 from dual union all
    select 'CTA','CTA - DELHI',37 from dual union all
    select 'CTA','CTA - HYDERABAD',10 from dual union all
    select 'CTA','CTA - KOLKATTA',22 from dual union all
    select 'CTA','CTA - MUMBAI',110 from dual
    select segment,
           case grouping_id(segment,units) when 0
                                           then units
                                           when 1
                                           then 'Sub total'
                                           else 'Grand total'
           end units,
           sum(total_items) total_items
      from the_data
    group by rollup(segment,units)
    SEGMENT
    UNITS
    TOTAL_ITEMS
    CRE
    CRE - MUMBAI
    3
    CRE
    Sub total
    3
    CTA
    CTA - DELHI
    37
    CTA
    CTA - MUMBAI
    110
    CTA
    CTA - CHENNAI
    13
    CTA
    CTA - KOLKATTA
    22
    CTA
    CTA - HYDERABAD
    10
    CTA
    Sub total
    192
    Grand total
    195
    Regards
    Etbin

  • Need help with the query -

    We have these two tables and trying to see if the amount in one table is equal to the sum of the amount fields in another table.
    Can someone please help?
    SQL> desc test;
    Name Null? Type
    KEY NUMBER(9)
    AMOUNT NUMBER(11,2)
    SQL> desc test1;
    Name Null? Type
    KEY NUMBER(9)
    TOTAL_AMOUNT NUMBER(11,2)
    SQL> select * from test;
    KEY AMOUNT
    1 10
    1 20
    1 70
    3 rows selected.
    SQL> select * from test1;
    KEY TOTAL_AMOUNT
    1 100
    1 row selected.
    SQL> select count(*) from test1 a where exists(select 'x' from test b where
    2 a.key=b.key and a.total_amount!=sum(b.amount));
    a.key=b.key and a.total_amount!=sum(b.amount))
    ERROR at line 2:
    ORA-00934: group function is not allowed here

    Hi,
    This would be so easy if there was a table like test that only had one row per key!
    You can make such a table, or you can just make a sub-query that has all the same data, and use that sub-query as if it were a table.
    For example:
    WITH  one_row_per_key_test  AS
        SELECT    key
        ,         SUM (amount)  AS total_amount
        FROM      test
        GROUP BY  key
    SELECT  COUNT (*)
    FROM    test1   a
    WHERE   EXISTS
            SELECT  'x'
            FROM    one_row_per_key_test  b
            WHERE   a.key          = b.key
            AND     a.total_amount = b.total_amount
            );There are lots of other ways to solve this particular problem (including HAVING), but this is a very important technique to know.

  • Help with the query---urgent

    PROCEDURE Mktg_Obj_Cmpgn(p_attr_tbl_nm IN attr.attr_tbl_nm%TYPE,p_actn_cd IN chg_log.actn_cd%TYPE) IS
    v_tbl_nm varchar2(100);
    v_actn_cd varchar2(4);
    BEGIN
    v_tbl_nm := p_attr_tbl_nm;
    v_actn_cd := p_actn_cd;
    --dbms_output.put_line(v_tbl_nm);
    IF v_actn_cd = 'CRET' THEN
    SELECT to_clob(XMLELEMENT("requestmessage",XMLATTRIBUTES(xmlforest(
    seq_pblsh_rqst.nextval AS "publish_id")),
    XMLAGG(XMLELEMENT("campaign",XMLATTRIBUTES(XMLFOREST(chg.actn_cd AS "ACTION",
    pgm.program_idseq AS "parententityvalue",
    ent_sbsrb.ENT_ID AS "entid",
    pgm.campaign_idseq AS "campaignid",
    bus_unt.portfolio_subtype_id AS "campaignsegment",
    pgm_typ.pgm_type_nm AS "campaigntype",
    LKP.lookup_key_desc AS "campaignclass",
    pgm.editor_userid AS "campaignlastmodifiedby",
    pgm.edited_dtm AS "campaignlastmodifieddate",
    pgm.mkt_initv_proc_tx AS "campaignlink",
    ofr.offer_idseq AS "offerlink")))),
    XMLAGG(XMLELEMENT("PROCESSCODE", XMLATTRIBUTES(XMLFOREST(action as "link",PROGRAM.program_idseq AS "parententityvalue",
    ENT_SBSRB_ATTR.ent_id AS "entid"))))))AS "v_clob" into v_clob1
    FROM dual,
    chg_log chg,
    program pgm,
    ent_sbsrb_attr ent_sbsrb,
    business_unit bus_unt,
    program_type pgm_typ,
    offer ofr,
    (SELECT lookup_keyword,lookup_key_desc,lookup_type
    FROM lookup_key
    WHERE lookup_type = 'PRTFL_CMPGN_ID')LKP
    WHERE chg.attr_id = ent_sbsrb.attr_id
    and chg.parnt_ent_val_tx = to_char(pgm.program_idseq)
    and pgm.business_unit_idseq = bus_unt.business_unit_idseq
    and pgm.pgm_type_cd = pgm_typ.pgm_type_cd
    and ofr.program_idseq = pgm.program_idseq
    and pgm.pgm_cls_cd(+) = LKP.lookup_keyword;
    END IF;
    end Mktg_Obj_Cmpgn;
    I have this procedure within a package. v_clob1 is declared in packagebody as a CLOB variable. when i try to compile it i am getting the below given error.can anyone please help me?
    (1): PL/SQL: ORA-19208: parameter 1 of function XMLELEMENT must be aliased
    (2): PL/SQL: SQL Statement ignored

    hi sir,
    wanna ask u guyz one query
    let say i have table name account(parent) and service(child)
    account
    id name status
    1 john 0
    2 ki 1
    3 kdf 2
    service
    id trans_id name status
    1 1 et 9999
    1 2 eee 2222
    2 3 ere 999
    2 4 wew 0
    i plan to use something like this
    delete account from account t1,service t2 where t1id=t2.id and t1.status<>0;
    but sql command not correct so plz help me
    now i need a query to delete records from service table only but
    account.status <> 0 and accound.id=service.id
    i dunt want to delete record from account table
    so can u help me with this query
    thanks
    Message was edited by:
    mani_um

  • Please help with the query (INSERT RETURNING BULK COLLECT INTO)

    I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
    Here is a full query that use in the C# code
    INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
    BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
    LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
    ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
    VALUES
    (SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
    :REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
    :SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
    :HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
    :CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
    :ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
    :STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
    However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
    Please help me resolve this error or I would appreciate a different solution
    Thank you

    You cannot use (and do not want to in this case) the BULK COLLECT.
    create table for_testing
       the_id      number not null primary key,
       some_data   number
    declare
       l_return_value for_testing.the_id%type;
    begin
      4 
       insert into for_testing
          the_id,
          some_data
       values
          1,
          5
       returning the_id into l_return_value;
       dbms_output.put_line('the return values is ' || l_return_value);
    end;
    20  /
    the return values is 1
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.02
    TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help in the Query

    I am trying to build a query with
    1)Customer name,Account number and monthly revenue.
    2) Customer name, Year-to -date revenue.
    I dont know which tables should i join to get the results.

    I dont know which tables should i join to get the results. Neither do we ;-).
    Without any details, no one will be able to help you.

  • Require help on the Query related to where condition

    Hi All,
    i am a java developer and was required to write a query for some of my operations to get the data from oracle database.
    i am stuck at one point. please help me.
    i have table with 3 columns.
    ID | Name | Value
    1 | ser | x
    1 | Bus | a
    1 | pol | b
    2 | ser | x
    2 | Bus | a
    2 | pol | c
    3 | ser | y
    3 | Bus | a
    3 | pol | b
    4 | ser | y
    4 | Bus | d
    4 | pol | e
    i have written query like below.
    Select ID from table where Name in ('ser','Bus','pol') and Value in ('x','a','b');
    i am getting out put as ID = 1,2,3
    but i should get the output as ID=1
    i should get the ID which satisfies all the given attributes and values.
    i cannot use the AND for each Name and Value here as i the no.of values inName or Value field may increase and that will be dynamically passed from my java class.
    Immediate help is appreciated.
    thanks a lot

    Something like this will deal with multiple values and treat the name value pairs together...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as ID, 'ser' as Name, 'x' as Value from dual union all
      2             select 1, 'Bus', 'a' from dual union all
      3             select 1, 'pol', 'b' from dual union all
      4             select 2, 'ser', 'x' from dual union all
      5             select 2, 'Bus', 'a' from dual union all
      6             select 2, 'pol', 'c' from dual union all
      7             select 3, 'ser', 'y' from dual union all
      8             select 3, 'Bus', 'a' from dual union all
      9             select 3, 'pol', 'b' from dual union all
    10             select 4, 'ser', 'y' from dual union all
    11             select 4, 'Bus', 'd' from dual union all
    12             select 4, 'pol', 'e' from dual)
    13  --
    14  -- end of test data
    15  --
    16      ,i as (select 'ser|x,Bus|a,pol|b' as r from dual)
    17  --
    18  -- end of input
    19  --
    20      ,split as (select regexp_substr(r,'[^,]+',1,rn) as pair
    21                 from   i
    22                        cross join (select rownum rn
    23                                    from dual
    24                                    connect by rownum <= (select length(regexp_replace(r,'[^,]'))+1 from i))
    25                )
    26  select id
    27  from t, split
    28  where name = regexp_substr(pair,'[^|]+',1,1)
    29  and   value = regexp_substr(pair,'[^|]+',1,2)
    30  group by id
    31* having count(*) = (select count(*) from split)
    SQL> /
            ID
             1It's then just a case of providing the input in the correct format.

Maybe you are looking for

  • CS4 - Master Collection download link

    I have a registered version on the master collection but purchased the disc version. My install disc is damaged and customer service says that they have no access to the download version of the product. Does anyone have a download version that I can

  • IPhone to Exchange calendar sync issues

    OK, I have read through many posts on here, but have yet to find a post that describes my situation. If someone has seen this answered in other places, please let me know. I currently have the following setup: iPhone 2.2.1, using OTA sync with Exchan

  • Saved Objects are not displayed in designer view after insert

    Hi All, My HFRS is acting weird today. I tried to insert a saved Object(text,Image) into my report. I have inserted them by (Insert>>Saved Object) but I'm unable to view them in designer view after insert. When I run the PDF Preview I'm able to see t

  • Flash Will NOT Install - Tech Note 19166 Didn't Work

    All of the sudden my Flash player stopped working in the browser. Use to work fine, then didn't one day. I get the "Failed to install" message referencing me to http://www.adobe.com/go/tn_19166 I've gone through every step at least 5 times with admin

  • R12 upgrade patch terminating abnormally

    I am applying R12 upgrade patch 6678700 and it is terminating abnormally.The patch session come to command prompt. The DB is one one node application is on another node.The database version is 11.2.0.3 and it is on linux OEL 5.5 64bit.Please help me