Materialized View Partitioning

I am creating a materialized view partitioned by range. The column is the grouping id. I have three different grouping sets. How do I defined partition values to make sure I am spreading my data as evenly as possible?
EX. PARTITION VALUES LESS THAN (???)
CREATE MATERIALIZED VIEW REALDW.CLAIM_LIFE_CUBE_MV
TABLESPACE MV_TABLES
NOLOGGING
PARTITION BY RANGE (GID)
PARTITION VALUES LESS THAN (100)
NOLOGGING
NOCOMPRESS
TABLESPACE MV_TABLES,
PARTITION VALUES LESS THAN (1000)
NOLOGGING
NOCOMPRESS
TABLESPACE MV_TABLES,
PARTITION VALUES LESS THAN (MAXVALUE)
NOLOGGING
NOCOMPRESS
TABLESPACE MV_TABLES
NOCACHE
NOPARALLEL
BUILD IMMEDIATE
USING INDEX
TABLESPACE MV_TABLES
REFRESH FORCE ON DEMAND
WITH ROWID
ENABLE QUERY REWRITE
AS
SELECT /*+ PARALLEL (CLAIM_LIFE_FACT, 2, 2) */ PAYER_KEY,
OFFICE_KEY,
CURRENT_CLAIM_STATUS_KEY,
INITIAL_CLAIM_STATUS_KEY,
BATCH_KEY,
PROCESS_TIME_KEY,
BATCH_SUBMIT_TIME_KEY,
OFFICE_START_DATE,
BATCH_SUBMIT_DATE,
DURATION_KEY,
ROUND(TIME_LAPSE),
GROUPING_ID(PAYER_KEY, OFFICE_KEY, CURRENT_CLAIM_STATUS_KEY, DURATION_KEY, INITIAL_CLAIM_STATUS_KEY,
BATCH_KEY, PROCESS_TIME_KEY, BATCH_SUBMIT_TIME_KEY, ROUND(TIME_LAPSE),
OFFICE_START_DATE, BATCH_SUBMIT_DATE) GID,
COUNT(*) COUNT_CLAIM_STAR,
AVG(TIME_LAPSE) AVERAGE_TIME_LAPSE,
COUNT(TIME_LAPSE) COUNT_TIME_LAPSE,
SUM(TOTAL_CHARGE_AMT) TOTAL_CHARGE_AMT,
COUNT(TOTAL_CHARGE_AMT) COUNT_CHARGE_AMT
FROM REALDW.CLAIM_LIFE_FACT
GROUP BY GROUPING SETS ((COLUMN LIST 1), (COLUMN LIST 2) (COLUMN LIST 3));
Thanks in advance.

<quote>Any advice?</quote>
Well, any problem?
I only glanced over the code you've included ... not sure what else I can do here except for building my own example replicating your scenario and determining if that range partitioning over grouping sets is indeed possible (I never had a need to do it … and don’t like speculating).
Your stated need is to get even data distribution over partitions ... sooo ...
1. hash partition (a power of 2 for the number of partitions) to get even distribution whatever your data (now and in the future)
2. range partition ... but that requires knowledge of the data (as it is right now and how will evolve in the future) in order to achieve that even distribution.
Since I don't know your data, I cannot help with #2. Hope it sounds fair.

Similar Messages

  • Fast Refresh in Materialized Views Partitioned

    Hi all.. I've a little problem... let's go into it:
    I have two tables:
    A dimension table , named D1
    A partitioned fact table, named F1
    I create two materialized views log in each of 2 tables.
    Ok.. Now, I created a Materialized View Partitioned, name MV_F1D1, with incremental refresh for it...
    I can create the Materialized View Partitioned with fast refresh, no problem here...
    First time Oracle make a Complete refresh, everything ok.. Then I make a
         BEGIN
              DBMS_SNAPSHOT.REFRESH('MV_F1D1','F');
         END;
    And everything goes well...
    But.. In my fact tables, I load the data with a temporary table, named F1_NP (Fact table no partitionated)
    with the data of the current month. Every week I do this:
    1) Load the data in F1_NP
    2) If the LAST_PARTITION_MM_YYYY not exists in F1, I add the partition to F1...
    3) ALTER TABLE F1 EXCHANGE PARTITION LAST_PARTITION_MM_YYYY WITH TABLE F1_NP
    And, this is the problem....
    After that process, the Log table of F1 is empty..
    When i'm trying to fast refresh the mv_F1D1, I got an error
         ORA-12097 changes in the master tables during refresh, try refresh:
    THis occurs when only I truncate a partition
    in the fact table too.
    Ok.. My only solution here is to make a complete refresh.. But I have only a new partition. I expected that with the PCT, Oracle let me
    do it a fast refresh.      
    I'm looking for a solution in the web, and I installed the utlxmnv.sql:
    1) Before add a partition in F1
    truncate table mv_capabilities_table;
    exec DBMS_MVIEW.EXPLAIN_MVIEW ( 'MV_F1D1' );
    select * from mv_capabilities_table;
    PCT Y
    REFRESH_COMPLETE Y
    REFRESH_FAST Y
    REWRITE Y
    PCT_TABLE Y F1
    PCT_TABLE N D1 2068 Relation is not partitioned.
    REFRESH_FAST_AFTER_INSERT Y
    REFRESH_FAST_AFTER_ONETAB_DML Y
    REFRESH_FAST_AFTER_ANY_DML Y
    REFRESH_FAST_PCT Y
    REWRITE_FULL_TEXT_MATCH Y
    REWRITE_PARTIAL_TEXT_MATCH Y
    REWRITE_GENERAL Y
    REWRITE_PCT Y
    PCT_TABLE_REWRITE Y F1
    PCT_TABLE_REWRITE N D1 2068 Relation is not partitioned.
    2) After truncate a partition in F1
    truncate table mv_capabilities_table;
    exec DBMS_MVIEW.EXPLAIN_MVIEW ( 'MV_F1D1');
    select * from mv_capabilities_table;
    PCT Y
    REFRESH_COMPLETE Y
    REFRESH_FAST Y
    REWRITE Y
    PCT_TABLE Y F1
    PCT_TABLE N D1 2068 Relation is not partitioned.
    REFRESH_FAST_AFTER_INSERT N F1 2077 Mv log is newer than last full refresh
    REFRESH_FAST_AFTER_INSERT N F1 2077 Mv log is newer than last full refresh
    REFRESH_FAST_AFTER_ONETAB_DML N 2146
    REFRESH_FAST_AFTER_ANY_DML N F1 2076
    REFRESH_FAST_AFTER_ANY_DML N 2161
    REFRESH_FAST_PCT Y
    REWRITE_FULL_TEXT_MATCH Y
    REWRITE_PARTIAL_TEXT_MATCH Y
    REWRITE_GENERAL Y
    REWRITE_PCT Y
    PCT_TABLE_REWRITE Y F1
    PCT_TABLE_REWRITE N D1 2068 Relation is not partitioned.
    BEGIN
              DBMS_SNAPSHOT.REFRESH('MV_F1D1','F');
    END;
    ORA-32313: REFRESH FAST of "MV_F1D1" unsupported after PMOPs
    any ideas? Can I fast refresh a MV partitioned (composed with a Table Dimension and Fact table)
    with PCT when I add data in the Dimension Table/add a partition in a Fact Table Partitioned?

    Look at ATOMIC_REFRESH option, if you set this to FALSE you may see performance gain as it'll use DIRECT PATH and TRUNCATE. Data will be unavailable while being refreshed though.
    Cheers
    Si

  • Dictionary for materialized view partitions

    Hi
    I created a materilaized view with partitions and i need to add partitions dynamicaaly using stored procedure for that i need to check whther the partiions with the same name existing.where can i see the partition names for a materilaized view is there any table like "USER_TAB_PARTITIONS"?.apologizes if the same query exists in the forum

    In your situation you can always query the dictionary ... using your experience/imagination regarding predicates.
    select *
      from dictionary
    where table_name like '%MVIEW%
        or table_name like '%PART%Regards
    Etbin

  • Refresh a materialized view partition

    Hi,
    We have Oracle 10.2.0.3 DB and have a fast refreshable MV.
    We are planning to list partition it and would like to know if a partition can be "individually" refreshed. I looked at the PL/SQL supplied packages doc (for dbms_mview) and DW guide and could not specifically find this information.
    Your help is appreciated.
    Thanks

    Thanks for your response. I understand that it refreshes the partition efficiently but I need the "refresh MV by partition" to satisfy the following requirement:
    We have a batch processing systems that run multiple batches at the same time (one per partition key)
    We put the MV on demand (its usually on commit during non-batch processin times).
    A Batch is run and when it is over, the mv is refreshed and put back to on commit.
    so far, only one was run and we have not had a problem. When multiple batches are run , if one job puts it back to commit when second job is still running, the second job starts to crawl.

  • Materialized view refresh and rollback segment

    Hi all,
    maybe this is a dumb question but:
    We use a few materialized views (partitioned, on prebult tables) in our DB.
    The refresh method used is complete.
    Every refresh clears old data et the very beginning and leaves the table empty until new data is commited (can take up to 2 hrs). But what is use of specifying the rollback segment than?
    I would like to change this behaviour to keep the old data to the very moment of replacing with new one.
    Is there a way?
    Thanks a lot
    Petr

    Hi all,
    maybe this is a dumb question but:
    We use a few materialized views (partitioned, on prebult tables) in our DB.
    The refresh method used is complete.
    Every refresh clears old data et the very beginning and leaves the table empty until new data is commited (can take up to 2 hrs). But what is use of specifying the rollback segment than?
    I would like to change this behaviour to keep the old data to the very moment of replacing with new one.
    Is there a way?
    Thanks a lot
    Petr Oracle will truncate the MV and then effectively insert as select to populate your MV. In doing so
    Oracle needs to keep a read consistent view of the select it is executing. Here clearly you might consider specifying a specific rbs.
    Have you considered fast refresh or is this not a candidate? At least with fast refresh you won't have to compeletly rebuild the mv each time and it will be considerably faster.
    steve

  • Materialized View  with Joins and Possibilities of Partitioning

    Hi,
    We have a materialized view which has a data to query around 12 gb. The query goes some thing like
    this.
      Select a.c1,a.c2,b.c1,b.c2,c.c1,c.c2
      from a,b,c
      where a.c1=b.c1
      --and the where condition goes on...
      --i.e Basically joining 3 different tables with complex join conditions but without any group functions and subqueries.
       Now i have few questions here.
    Firstly as the Mview is created with joins we will have to create separate logs for each tables and we have did the same. The logs are created with rowid and sequence for better performance during refresh.
    Question No 1
    Is this is a best approach for materializing a query with complex join conditions. Or Is it better to make 3 different materialized views for each 3 tables and join those 3 MViews and write a query for my report. I ask this question just to make sure the refresh time is brought down by this method. But as such as we have created 3 different logs for 3 tables the refresh must be happening separately.
    Question No 2
    Data is likely to grow faster and faster on this. So we have a idea of making this a partitioned Mview. Can the Pro's advice me on this and suggest me the right practice for the same and help me to correct links from where i can pick a example and continue from there.
    Question No 3
    How to find whether the materialized view has refreshed on a fast mode or complete mode after the last refresh.
    Apart from querying and checking the rowid which i feel is quiet cumbersome for a mview with a data volume like what we have. By default when i see the info in TOAD for this Mview it shows Refresh Mode as "Force". But how to ascertain this.
    Thanks in anticipation for a good round of discussion

    Hi,
    We have a materialized view which has a data to query around 12 gb. The query goes some thing like
    this.
      Select a.c1,a.c2,b.c1,b.c2,c.c1,c.c2
      from a,b,c
      where a.c1=b.c1
      --and the where condition goes on...
      --i.e Basically joining 3 different tables with complex join conditions but without any group functions and subqueries.
       Now i have few questions here.
    Firstly as the Mview is created with joins we will have to create separate logs for each tables and we have did the same. The logs are created with rowid and sequence for better performance during refresh.
    Question No 1
    Is this is a best approach for materializing a query with complex join conditions. Or Is it better to make 3 different materialized views for each 3 tables and join those 3 MViews and write a query for my report. I ask this question just to make sure the refresh time is brought down by this method. But as such as we have created 3 different logs for 3 tables the refresh must be happening separately.
    Question No 2
    Data is likely to grow faster and faster on this. So we have a idea of making this a partitioned Mview. Can the Pro's advice me on this and suggest me the right practice for the same and help me to correct links from where i can pick a example and continue from there.
    Question No 3
    How to find whether the materialized view has refreshed on a fast mode or complete mode after the last refresh.
    Apart from querying and checking the rowid which i feel is quiet cumbersome for a mview with a data volume like what we have. By default when i see the info in TOAD for this Mview it shows Refresh Mode as "Force". But how to ascertain this.
    Thanks in anticipation for a good round of discussion

  • Materialized view and Partition

    Hi,
    I want to discuss a scenario, with which i am dealing nowadays. there is only a single table (named livecdr ) has 22-23 fields and the records are updating in every sec (on daily basis) and in 24hrs livecdr contains approximately more than 2 crore records.
    Problem is that the query processing time is so slow due to large number of records and query is fetching records from a view created on livecdr table. I want to know the options, how the query would fetch these records in a short time. Firstly i did range partitioning on livecdr and then i created materlized view but the view didn't create on partition table and when i removed partitioning it was created. After view creation, query performance is much better. i also applied indexing on livecdr.
    Can you please tell me, whether this approach is okay or i am doing mistake. should i create partitioning on materialized view and how would i select records from view if partitioning would be applied on materialized view. Please guide me with best approaches.
    thankyou.

    Hello,
    Here is how I created partitioned table (monthly partitions) and partitioned mview on the table. This is just an example you might have to change the mview partitions from monhtly to yearly or quartely.
    CREATE TABLE live_cdr
       CALLID              VARCHAR2 (20),
       CD                  VARCHAR2 (25),
       CG                  VARCHAR2 (25),
       RE                  VARCHAR2 (25),
       OPC                 VARCHAR2 (12),
       DPC                 VARCHAR2 (12),
       STIME               VARCHAR2 (25),
       SDATE               DATE,
       ATIME               VARCHAR2 (25),
       ADATE               DATE,
       ETIME               VARCHAR2 (25),
       EDATE               DATE,
       schangeTime         VARCHAR2 (25),
       schangeDate         DATE,
       STATUS              VARCHAR2 (25),
       bucket              NUMBER (20),
       CIC                 NUMBER (20),
       charge              VARCHAR2 (30),
       ported              VARCHAR2 (30),
       jurisdiction_Info   VARCHAR2 (30),
       origLine_Info       CHAR (1),
       Variant             NUMBER,
       auto_inc            NUMBER
    PARTITION BY RANGE (EDATE)
      PARTITION LIVE_CDR_JAN_2009 VALUES LESS THAN (TO_DATE(' 2009-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
        LOGGING
        NOCOMPRESS, 
      PARTITION LIVE_CDR_FEB_2009 VALUES LESS THAN (TO_DATE(' 2009-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
        LOGGING
        NOCOMPRESS
    );Mview definition
    CREATE MATERIALIZED VIEW KLONDIKE.LIVE_CDR_MV
    LOGGING
    PARTITION BY RANGE (EDATE)
      PARTITION LIVE_CDR_MV_JAN_2009 VALUES LESS THAN (TO_DATE('20090201',
          'YYYYMMDD'))
        LOGGING
        NOCOMPRESS,
      PARTITION LIVE_CDR_MV_FEB_2009 VALUES LESS THAN (TO_DATE('20090301',
          'YYYYMMDD'))
        LOGGING
        NOCOMPRESS
    BUILD IMMEDIATE
    REFRESH COMPLETE
    START WITH SYSDATE
    NEXT SYSDATE  + 2 /24
    AS
    SELECT   DISTINCT (ic.callid) callid,
                      ic.CG,
                      ic.CD,
                      ic.RE,
                      ic.OPC,
                      ic.DPC,
                      ic.SDATE,
                      ic.STIME,
                      ac.ADATE,
                      ac.ATIME,
                      ec.ETIME,
                      ec.EDATE,
                      ec.STATUS
      FROM   live_cdr ic, live_cdr ac, live_cdr ec
    WHERE       ic.callid = ac.callid
             AND ic.callid = ec.callid
             AND ic.stime = ac.stime
             AND ic.stime = ec.stime
             AND ic.sdate = ac.sdate
             AND ic.sdate = ec.sdate
             AND ac.ADATE IS NOT NULL
             AND ec.EDATe IS NOT NULL
             AND ec.etime IS NOT NULL
             AND ic.CD IS NOT NULL
             AND ic.cg IS NOT NULL;Regards

  • Create a fast refresh materialized view with partitioned primary index

    Hi,
    I have a materialized view that is based on a table with primary key.
    I want to create a materialized view with a partitioned primary index . do you have any way of doing it?
    I tried to create a materialized view with rowid and then I created a partitioned primary index on it.
    It did not work as what I expected. I could not perform a fast refresh on it. the materialized view can only complete refresh
    thank you

    Hi,
    Here is some info from the Oracle Documentation.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10706/repmview.htm
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10810/basicmv.htm
    Determining the Fast Refresh Capabilities of a Materialized View
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10706/repmview.htm#BABEDIAH
    Regards,

  • Materialized View Log - Compress Clause for List Partition

    Hi All,
    In Syntax diagram it states that Compress Clause for List Partition of Materialized View Log is valid , but when we run any script with compress clause for list partition on Materialized view log then Database throws error as ORA-14020: this physical attribute may not be specified for a table partition
    So in any chance we can have the compress clause for the partition of materialized view log.
    Thanks in advance,
    Manu.

    The "CREATE MATERIALIZED VIEW LOG" syntax refers to the "Table Partitioning" section of the CREATE TABLE documentation.
    The "Table Partitioning" section refers to "table_partition_description" which then refers to "table_compression". "table_compression" then states that you can specify compression for entire table in the physical_properties clause and for range partition / list partition in the "table_partition_description". The Restrictions section on Table Compression says "You cannot define table compression explicitly for hash partitions or hash and list subpartitions" which implies that you can define partition for list partitions.
    Moreover, error 14020 lists valid options for Range or Composite Range and for Hash partitoins -- which implies that all other Table physical attributes are applicable for List partitions. (But then, is Compression a physical attribute -- it is really part of "physical properties" not "physical attributes").
    I think that the documentation isn't explicit enough and needs to be fixed.
    N.B : Referencing the 10.2 documentation.
    Hemant K Chitale
    Edited by: Hemant K Chitale on Feb 1, 2010 4:12 PM

  • Refresh FAST for Materialized View failed after Partition Operation

    Dear all,
    I have created a Materialized View having a simple join between a Dimension and Fact Table of a Datawarehouse. The MV is REFRESH FAST ON DEMAND.
    However, when a Partition Maintenance Operation (PMOP) was performed on the Master Tables, the MV failed to Refresh giving a ORA-32313 error.
    As suggested on one of the troubleshooting websites, we did a complete refresh of the MV and fixed it temporarily. However, I would like to know the exact cause for this and would like to have a permanent fix for the same.
    Can the DBA for this Database provide me the answers or are there some standard troubleshooting steps for the same?
    Please let me know.
    Best,
    Ketan

    Hello Maurice,
    Here are the answers to your questions.
    1) Database is Oracle 9i.
    2) We have a stored procedure to refresh the MV. The command is dbms_mview.refresh('SALES_FACT_MV','f'). It was working fine daily. Only after a PMOP was done on the Master Tables, it failed to refresh. We have also created indexes on some columns of the MV for performance improvement. We are getting a very good improvement.
    3) We have MV logs for both Master Tables to store the incremental values.
    4) We are not able to get the output from DBMS_MVIEW.EXPLAIN_MVIEW since this can be done only by the DBA. WIll update you once I have the info.
    5) Same as Point 2.
    Let me know if you need any further info.
    Thanks, Ketan

  • The data of my materialized view....in the while

    Hello
    We have problems with materialized views
    We have one wich re-build each a short period of time
    ¿Can i avoid the data to dissapear in the time process of refresh?
    Is so annoing to our clients to see that "from time to time" the data just dissapear for one period of time -the time while the materialized view is refreshing-
    Thank you in advance
    Bruno. Madrid. Spain

    > Is so annoing to our clients to see that "from time to time" the data just dissapear for
    one period of time -the time while the materialized view is refreshing-
    Have a similar problem. And dealing with large data volumes that makes the DELETE of the MV a very undesirable feature. Not as much a the resource footprint required, but the time it takes to do this - and the very tight processing windows that exist.
    The solution is a self-rolled and very likely not ideal for most - but it works well enough for us in production.
    No MV. Create a partition table. Create a staging table. Do a manual "full refresh" of the staging table (TRUNCATE and direct path INSERT). Follow this by a partition exchange with the partition table (no validation and including indexes). The result is that the data is replaced in the partitioned table within a second - no long running and expensive DELETE. End-users not effected by having a truncate pulling the data from beneath their reports.

  • Select query in materialized view with two dblinks

    Hi All,
    We have oracle 10g On windows.
    We are trying to create materialized view. Scenario is we have base table on other database and we are creating mview on different database.
    Basa database have two schema's and i am selecting records from that two schema's using two private db links.
    But when i am tryin gto create mview its not getting created. After 15 hrs. its still showing creation command and not finished.
    Query is :-
    Is it good practice to have two db links in select query of materialized view.

    Billy  Verreynne  wrote:
    Chanchal Wankhade wrote:
    Is it good practice to have two db links in select query of materialized view.Same db link being used twice, or two different db links?
    If the former, you ideally want the local Oracle db to send the join to the remote database, and for the remote database to drive the join between those 2 tables. There is a hint (<i>driving_site</i>) that can be used - or the join query can be defined on the remote database as a view, and the local materialised view can then use that remote view.
    If you have 2 different db links and joining across these - usually a bad idea to perform distributed database joins. There are lots of limitations as to how the tables can be joined. Worse case, full table scans of both remote tables, pulling all the rows from the 2 remote database tables to the local database, and joining these on the local database.
    I have seen some severe performance issues in the past as a result of distributed joins. I'll rather use 2 materialised views for pulling both distributed tables's data locally, and then do the join on local data (using indexes, partition pruning, etc)Hi Billy,
    My scenario is i have two database database A and database B. Database A is having two schema's SCOTT AND HR. SCOTT schema have select privileges on HR schema.
    DB LINK is between Database B to Database A. name is db.link.B.A.oracle.com.
    What if i priovide while creating materialized view, the schema name before the table name in database B for this particuler table so it will pick up the table from that schema using same DB LINK(db.link.B.A.oracle.com.) that i am using to fetch records from SCOTT schema.
    Above schnario is like two base schema's and one db link using two schema.

  • Leave a distinct value in a materialized view on two tables

    Hi and thank you for reading,
    I have the following problem. I am creating a materialized view out of two tables, with "where a.id = b.id".
    The resulting materialized view list several values twice. For example, one customer name has several contact details and thus the customer name is listed several times. Now I would like to join each customer name with just ONE contact detail, how can I do that? (Even if I would loose some information while doing this).
    Thanks
    Evgeny

    Hi,
    You can do this
    SELECT   deptno, empno, ename, job, mgr, hiredate, sal, comm
        FROM emp_test
    ORDER BY deptno;
        DEPTNO      EMPNO ENAME      JOB              MGR HIREDATE          SAL       COMM
            10       7782 CLARK      MANAGER         7839 1981-06-09       2450          
            10       7839 KING       PRESIDENT            1981-11-17       5000          0
            10       7934 MILLER     CLERK           7782 1982-01-23       1300          
            20       7566 JONES      MANAGER         7839 1981-04-02       2975          
            20       7902 FORD       ANALYST         7566 1981-12-03       3000          
            20       7876 ADAMS      CLERK           7788 1987-05-23       1100          
            20       7369 SMITH      CLERK           7902 1980-12-17        800          
            20       7788 SCOTT      ANALYST         7566 1987-04-19       3000          
            30       7521 WARD       SALESMAN        7698 1981-02-22       1250        500
            30       7844 TURNER     SALESMAN        7698 1981-09-08       1500          
            30       7499 ALLEN      SALESMAN        7698 1981-02-20       1600        300
            30       7900 JAMES      CLERK           7698 1981-12-03        950          
            30       7698 BLAKE      MANAGER         7839 1981-05-01       2850          
            30       7654 MARTIN     SALESMAN        7698 1981-09-28       1250       1400
    14 rows selected.
    SELECT CASE
              WHEN ROW_NUMBER () OVER (PARTITION BY deptno ORDER BY empno) =
                                                                         1
                 THEN deptno
           END deptno,
           empno, ename, job, mgr, hiredate, sal, comm
      FROM emp_test;
        DEPTNO      EMPNO ENAME      JOB              MGR HIREDATE          SAL       COMM
            10       7782 CLARK      MANAGER         7839 1981-06-09       2450          
                     7839 KING       PRESIDENT            1981-11-17       5000          0
                     7934 MILLER     CLERK           7782 1982-01-23       1300          
            20       7369 SMITH      CLERK           7902 1980-12-17        800          
                     7566 JONES      MANAGER         7839 1981-04-02       2975          
                     7788 SCOTT      ANALYST         7566 1987-04-19       3000          
                     7876 ADAMS      CLERK           7788 1987-05-23       1100          
                     7902 FORD       ANALYST         7566 1981-12-03       3000          
            30       7499 ALLEN      SALESMAN        7698 1981-02-20       1600        300
                     7521 WARD       SALESMAN        7698 1981-02-22       1250        500
                     7654 MARTIN     SALESMAN        7698 1981-09-28       1250       1400
                     7698 BLAKE      MANAGER         7839 1981-05-01       2850          
                     7844 TURNER     SALESMAN        7698 1981-09-08       1500          
                     7900 JAMES      CLERK           7698 1981-12-03        950          
    14 rows selected.Edited by: Salim Chelabi on 2009-09-14 08:13

  • Dynamic calculations in a materialized view

    Hi,
    I have a problem. I created a materialized view which works perfectly. But now I need to perform some calculations with the data in my view . The view contains the working hours of employees who worked in different projects. Every project has a fixed amount of time (time_available) in which the employee has to finish the project. I aggregated the working hours to month for better presentation. What I want to accomplish here is a "simple" subtraction of "fixed amount for a project" minus "working hours" for the employee.
    The problem here is that some project have duration of more that just one month. Naturally all my values are in one tuple for every month. So when I have 3 month of working hours for a project my view looks like this:
    MV_Working_Hours:
    Project --- Time_Available --- DATE --- Employee --- Working Days
    Project A --- 50 Days --- 2011-05 --- Mr. A --- 15 Days
    Project A --- 50 Days --- 2011-06 --- Mr. A --- 16 Days
    Project A --- 50 Days --- 2011-07 --- Mr. A --- 16 Days
    What I want to do is to calculate the remaining days like this :
    Project --- Time_Available --- DATE --- Employee --- Working d in Month ---reaming days
    Project A --- 50 Days --- 2011-05 --- Mr. A --- 15 Days --- 35 Days
    Project A --- 50 Days --- 2011-06 --- Mr. A --- 16 Days --- 19 Days <--- I get here 34 which is for my need wrong !!!
    Project A --- 50 Days --- 2011-07 --- Mr. A --- 16 Days --- 3 Days
    Is there a way to realize this with "just" sql or do I have to use pl/sql in the OWB? I use the OWB version 11gR2
    thx

    For everybody who is confronted with the same problem I have - here is the solution: (thx to "spencer7593" and "Justin Cave" from StackOverflow)
    SUM( "Working Days" )
    OVER (PARTITION BY "Product", "Employee"
    ORDER BY "DATE"
    ROWS UNBOUNDED PRECEDING)
    and please check out the link from oracle for _"SQL for Analysis and Reporting"_: http://download.oracle.com/docs/cd/E14072_01/server.112/e10810/analysis.htm

  • Subquery in a Materialized View

    I have a requirement where we have to build a summary view to show a customer's latest transaction. There can be several million customers so I am thinking if a Materialized view that gets refreshed once every day is a good option here. This is a Datawarehouse application where the records get appended once every day. I would like a summarized materialized view that is dropped and refreshed every day morning.
    Here is the query that gets the latest order amount for each of the customer:
    SELECT cu.cust_name,
    od.order_amount
    FROM customers cu,
    orders od
    WHERE cu.cust_id = od.cust_id
    and od.order_date =
    (select max(order_date) from orders od
    where od.cust_id = cu.cust_id)
    My questions are:
    1) Is the materialized view a snapshot? Or does it go against the underlying table every time the MV is accessed, much like a regular view?
    2) I would like a snapshot type of solution here. Since there could be 100 million orders for 1 million customers, a summary snapshot of 1 million records would perform much better IMO. Correct me if I got it wrong.
    Thank you in advance for your help.

    Users query will be explicitly against the Mview.
    After doing some reading on the MView, I am more inclined to think that Mview is not an ideal solution for my requirement here.
    SELECT cu.cust_name,
    od.order_amount,
    MAX(od.order_date) over (PARTITION BY od.cust_id) max_date
    FROM customers cu,
    orders od
    WHERE cu.cust_id = od.cust_id
    The orders is a 20+ million records table. I thought by using a Mview that holds the maximum order date will avoid going to the orders table when users want to see that is the latest order date for a customer. However, the report requirements are such that the users will want to see what is the maximum order date within a certain date range. If this being the case, there is no point in using an Mview.
    Once again, pl correct me if my understanding is not correct.

Maybe you are looking for