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 ...

Similar Messages

  • Help with sql query on materialized view logs

    I am in need of a query to find out what tablespace and snap shot site a long list of materialized view logs are associated with.
    something like below except tablespace and snap_shot_site are not an option for this table.
    select log_owner, master, log_table, tablespace, snap_shot_site from dba_mview_logs;

    What is the refresh method set as?
    Could you paste the full MV log creation script and the corresponding MV creation script.

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

  • 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                                                        
                    

  • Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be ab

    Hi, please help with the installation of Lightroom 4, I bought a new Mac (Apple) and I want to install a software that I have on the album cd. My new computer does not have the drives. Can I download software from Adobe? Is my license number just to be able to download the srtony adobe.

    Adobe - Lightroom : For Macintosh
    Hal

  • UPDATING the query in materialized view

    Hi,
    i have a little doubt in Materialized view. i created a materialized view and log with the following query,
    create table test_mv (a number ,b number )
    alter table test_mv add constraint t_pk primary key ( a );
    insert into test_mv values (1,2);
    insert into test_mv values(2,2);
    insert into test_mv values(3,2);
    insert into test_mv values(4,2);
    insert into test_mv values(5,2);
    commit;
    CREATE MATERIALIZED VIEW LOG ON test_mv
    WITH SEQUENCE, ROWID
    *(a,b)*
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW product_sales_mv
    ENABLE QUERY REWRITE
    AS SELECT  b  from test_mv;
    Now i want to update the query in the MV as 'Select a from test_mv' . for that i tried with
    *'ALTER MATERIALIZED VIEW product_sales_mv AS SELECT a from test_mv;'*
    But it throwing error,
    Error starting at line 5 in command:
    alter  MATERIALIZED VIEW product_sales_mv   AS SELECT  b  from test_mv
    Error report:
    SQL Error: ORA-00933: SQL command not properly ended
    +00933. 00000 - "SQL command not properly ended"+
    *Cause:+   
    *Action:+
    i guess i am doing wrong. kindly help me here. i want to update it without drop and recreate.
    thanks,
    Jeevanand.Ke

    Hi Jeeva,
    No. you cannot add or drop columns to the materialized view using the ALTER Statement.
    To Change the Structure of the view , drop and re-create the materialized view.
    To Alter a materialized view log, You can use the ALTER MATERIALIZED VIEW LOG. By this,
    You can add new columns to a materialized view log.
    ALTER MATERIALIZED VIEW LOG ON sggi_mrps.emp ADD(deptno);Thanks,
    Shankar
    Edited by: Shankar Viji on Aug 24, 2012 2:11 AM

  • Please help with a query

    select * from testme;
    NAME VAL
    A 1
    A 2
    A 3
    B 1
    B 2
    B 3
    C 1
    C 2
    I want to get the maximum of name and the maximum of corresponding name's value.
    ie., the answer should be
    Name VAL
    C     2
    Please help me with the query.
    Thnx

    SQL> create table testme
      2  as
      3  select 'A' name, 1 val from dual union all
      4  select 'A', 2 from dual union all
      5  select 'A', 3 from dual union all
      6  select 'B', 1 from dual union all
      7  select 'B', 2 from dual union all
      8  select 'B', 3 from dual union all
      9  select 'C', 1 from dual union all
    10  select 'C', 2 from dual
    11  /
    Tabel is aangemaakt.
    SQL> select max(name) name
      2       , max(val) keep (dense_rank last order by name) val
      3    from testme
      4  /
    NAME VAL
    C      2Regards,
    Rob.

  • Please help with tricky query

    I need help with SQL query (if it can be accomplished with query at all).
    I'm going to create a table with structure similar to:
    Article_Name varchar2(30), Author_Name varchar2(30), Position varchar2(2). Position field is basicly position of an article author in the author list, e.g. if there is one author, his/her position is 0, if 2, then 1st author is 0, second is 1, etc.
    Article_Name Author_Name Position
    Outer Space Smith 0
    Outer Space Blake 1
    How can I automate creation of Position, based on number of authors on the fly? Let's say I have original table without Position, but I want to create a new table that will have this information.
    Regards

    If you have an existing table whose structure doesn't tell you what position the author is in, what's the algorithm you'd use to determine who was the first author, the second author, etc? If you issue a select query on a table without providing an "order by" clause, Oracle makes no guarantees about the order in which it retrieves rows.
    As an aside, why would you store position number in a varchar2 field? If it's a number, it ought to be stored as a number.
    Justin

  • 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 needed in query for Materialized View

    Hi,
    I want to create a materialized view which has some precalcultaed values.
    I have four dimension tables out of which one is a Time Dimension table with levels as Year->Quarter->Month.
    The precalculations are the moving averages and cummulative values of Sales Amt on the dimension values over a period of 4 Months.
    The dimension tables are Clients, Products, Channel, Time.
    Fact Table is Sales_Fact which will have the sales amount for different members of the dimension.
    Since my fact table is very huge, i want to create a materialized view where i could store the required calculated measures, here Moving Average of Sales Amt for each Client, Product, Channel dimensions over a period of 4 Months.
    Can anybody help with writing the query for this..Any help in this regard will be appreciated..
    Please give me suggestions for this..

    Check this link.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1612
    Regards
    Raj

  • Please help with some query

    hello all!
    please, help me again.
    we have a foreign key discrepancy and my task is to create a view which will show the 3 aspects.
    Let's we have 3 schemas: A - good (which means that i will compare WITH A, source)
    B and C are bad (which mean that I will checking this schemas).
    So, i need to obtain:
    1) FK that DO NOT exist in B&C and do exist in A
    2) FK that DO exist in bad schemas (B&C) but DO NOT exist in good schema (A)
    3) FK's that exist in both (A&B, A&C) schemas on the SAME TABLE, have THE SAME CONSTRAINT_NAME but are on the DIFFERENT columns.
    the first and second I seem to be done through the
    select CONSTRAINT_NAME, TABLE_NAME, STATUS from dba_constraints where owner='PRIV_MD' and CONSTRAINT_TYPE='R' and CONSTRAINT_NAME
    2 NOT IN (select CONSTRAINT_NAME from dba_constraints where owner ='MSA_MD'); (to get the second task we just reversing owners in query and subquery)
    query. but the third one is really pain in my back. i have a query:
    SELECT a.column_name, b.column_name FROM dba_cons_columns a, dba_cons_columns b, dba_constraints c, dba_constraints d
    WHERE c.CONSTRAINT_TYPE='R'
    AND a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
    AND a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
    AND b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
    AND a.owner = 'PRIV_MD' AND b.owner = 'MSA_MD';
    which runs hours and returns million of rows with the two columns with the same names... but if i'm adding
    AND a.column_name != a.column_name (i'm not sure it's a correct syntax)
    line it returns "no rows selected"
    please, help me obtain it, i'm fighting already the second day..
    (please, don't be angry, i'm just learning and this is my first task on my work...)

    This is basically just a UNION ALL (the constraint columns from both schemas)
    MINUS what exists in both (the INTERSECTion)
    I made it a little more complicated so you could see in which schema the column is used. You could use exactly the same approach for your questions 1 and 2 also.
    SELECT * FROM
    (SELECT a.column_name,c.constraint_name,'salive' schema_containing
    FROM dba_cons_columns a
    INNER JOIN dba_constraints c ON a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
    WHERE a.owner = 'SALIVE' and c.constraint_type = 'R'
    UNION ALL
    select b.column_name,d.constraint_name,'satest'
    FROM dba_cons_columns b
    INNER JOIN dba_constraints d ON b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
    WHERE d.CONSTRAINT_TYPE='R' AND b.owner = 'SATEST') u
    WHERE NOT EXISTS
    (SELECT *
    FROM
    (SELECT a.column_name,c.constraint_name
    FROM dba_cons_columns a
    INNER JOIN dba_constraints c ON a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
    WHERE a.owner = 'SALIVE' and c.constraint_type = 'R'
    INTERSECT
    select b.column_name,d.constraint_name
    FROM dba_cons_columns b
    INNER JOIN dba_constraints d ON b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
    WHERE d.CONSTRAINT_TYPE='R' AND b.owner = 'SATEST') i
    WHERE u.column_name = i.column_name and u.constraint_name = i.constraint_name)

  • Please Help - How do I create a VIEW through a trigger

    I'm trying update a view under the following circumstances
    I have a table, TABLE1, with about 50 columns. I have another table, TABLE2, with a list of columns from TABLE1 that I want to include in the view. Whenenver I add or delete an entry in TABLE2, I want to update the view with the new set of columns from TABLE1.
    I'm getting "cannot commit in trigger" (ORA-04092) error.
    Please help
    I tried the following trigger and the procedure
    TRIGGER
    CREATE OR REPLACE TRIGGER MAPPING_FIELDUPDATE
    AFTER insert or DELETE OR update of DISPLAY_COLUMN_NAME, TABLE1_COLUMN_NAME
    on TABLE2
    begin
    TABLE1_MAPPING;
    end;
    Procedure TABLE2_MAPPING
    IS
    CURSOR MYCUR IS SELECT * FROM MYDATBASE.TABLE1;RowInfo MYCUR%ROWTYPE;
    FIELDLIST VARCHAR2(5000);
    SQLSTRING VARCHAR2(5000);
    BEGIN
    OPEN MYCUR;
    LOOP
    FETCH MYCUR INTO RowInfo;
    EXIT WHEN MYCUR%NOTFOUND;
    IF (FIELDLIST IS NULL) THEN
    FIELDLIST :=RowInfo.TABLE1_COLUMN_NAME||' '||RowInfo.DISPLAY_COLUMN_NAME;
    ELSE
    FIELDLIST :=FIELDLIST||','||RowInfo.TABLE1_COLUMN_NAME||' '||RowInfo.DISPLAY_COLUMN_NAME;
    END IF;
    END LOOP;
    CLOSE MYCUR;
    SQLSTRING:= 'CREATE OR REPLACE VIEW SELECTTABLE1 AS SELECT '||FIELDLIST||' FROM TABLE1';
    DBMS_OUTPUT.PUT_LINE(SQLSTRING);
    EXECUTE IMMEDIATE SQLSTRING;
    END;

    or does anybody know any work-around.Sure. Don't use a trigger to create a view. Build a view that selects from a function that returns a ref cursor. Have the function assemble the query dynamically from the values in TABLE 2.
    Although I still think this kind of dynamic configuration is a design smell.
    Cheers, APC

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

  • Please help with RecordSet Query

    Hello all. I am trying to build a contact management system
    for different offices. Each person has a login they use to access
    their office's respective page. What I am wanting to do is pull up
    all the employees' information that work at the same location as
    the person who logged in. For example: Person A, B, and C work at
    Location 1 and Person X, Y, and Z work at location Z. If person A
    logs in, I want the to be able to see the dynamic table with the
    information for all of Location 1 (Person A, B, and C). I
    understand using the session variable MM_Username to filter the
    recordsets based off who logs in. Where I'm confused is in pulling
    up the records for everyone that shares the same location as the
    person who logs in. In other words, if I say filter Information
    based off Session Variable MM_Username it only returns the
    information for the person who logged in. I want it to say, in
    layman terms, Person A logged in, now look at their location, and
    return all Person's information who has a location equal to that of
    Person A. I hope I explained my dilemma clearly enough. If I need
    to elaborate or explain any more please let me know. Thanks in
    advance for any and all help.

    Thank you for your help. Sorry for my ignorance, but I'm
    still confused. I've made some changes to hopefully help. I have 1
    SQL table (called "Employees") with TableID, Username, Password,
    AccessLevel, and LocationID. I have another table (called
    "Names"-for testing purposes) with just TableID, Name, and
    LocationID. The query that I built, which doesn't work, is:
    SELECT `Names`.`Names`
    FROM Employees, `Names`
    WHERE Employees.Store_Number = `Names`.Store_Number
    I'm wanting it to simply display the names from the Names
    table that share the same LocationID as in the Employees Table. I
    realize that at this point it should just be a list of all the
    employee names from the Names table, but what it's doing is
    actually displaying 2 of every name. What do I need to do to set
    this up to where the MM_Username Session Variable generated at
    login grabs the LocationID from the Employee Table, then uses that
    LocationID and displays all the names from the Names Table with
    that same LocationID? I'm sorry for my lack of understanding, and I
    really appreciated the help.
    As a side note, why are there apostrophes around the Name
    Table but not the Employees Table in the query window? Thank you
    again.

Maybe you are looking for

  • How to get af:commandLink components of a page in its showPrintablePage

    I have a table which has af:commandLink component in one of its column. Other columns have af:outputText components which are visible in show printable page of the table..But the column which has af:commandLink component in it shows blank.Is there an

  • BEA / Wily:  Financial Webinar - Achieving Availability, Performance and Control of Java Applications in Financial Services

    Event Date: October 1, 2002 at 11:00 AM Pacific (US), 02:00 PM Eastern (US) To register: http://regsvc.placeware.com/?wily-bea1001 Title: Achieving Availability, Performance and Control of Java Applications in Financial Services Abstract: In today's

  • Error starting WebLogic Server from Workshop

    I get the following error when trying to start WebLogic server from within Workshop. Any ideas? Also, it looks like the sample code that came with the first beta is no longer there - is that supposed to be the case? Build # 2002.0423.3 Values from Wo

  • Viewing Sent Mail Causes Mail to Quit Unexpectedly

    I am on an iMac, OS X 10.6.8 using Mail 4.5.  I have two different email accounts that I use.  No problems with sending messages, but I can not view the copy in the Sent folder for either mailbox.  When I try to open a Sent message, Mail crashes with

  • 404 Listener Error

    We are running Oracle Portal 3.0 in a Windows 2000 environment connecting to Oracle8i Enterprise Edition database Release 8.1.6.1.0. The problem: 1 - Login to the administration side. 2 - Click on the Navigator icon at the top of the screen. 3 - Clic