DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Create Materialzed view using WITH clause

  1. #1
    Join Date
    Feb 2006
    Posts
    162

    Create Materialzed view using WITH clause

    Hi All,

    How to create the Materialzed view using WITH clause? Using the below given code,
    I'm not able to create the MV and it is disconnecing when trying to create the MV with the below code.

    CREATE MATERIALIZED VIEW activity_mv
    TABLESPACE DATA BUILD DEFERRED REFRESH FORCE ON DEMAND
    WITH ROWID AS
    WITH sum_sal AS (SELECT deptno , SUM(sal)sal_sum FROM emp GROUP BY deptno ),
    cnt_emp AS (SELECT deptno , COUNT(sal)cnt_sal FROM emp GROUP BY deptno )
    SELECT emp.deptno, emp.ename ,empno, sal
    FROM emp , sum_sal rec1 , cnt_emp rec2
    WHERE emp.deptno = rec1.deptno
    AND rec1.deptno = rec2.deptno
    AND sal > (sal_sum/cnt_sal )

    Please let me know how to create it successfully and Oracle version is 9.2.0.7

    Thanks...

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Create Materialized View command requires a valid SELECT statement to populate it ... what happens if you run your populate statement independently?
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    Oct 2006
    Posts
    175
    Quote Originally Posted by malru View Post
    Hi All,

    How to create the Materialzed view using WITH clause? Using the below given code,
    I'm not able to create the MV and it is disconnecing when trying to create the MV with the below code.

    CREATE MATERIALIZED VIEW activity_mv
    TABLESPACE DATA BUILD DEFERRED REFRESH FORCE ON DEMAND
    WITH ROWID AS
    WITH sum_sal AS (SELECT deptno , SUM(sal)sal_sum FROM emp GROUP BY deptno ),
    cnt_emp AS (SELECT deptno , COUNT(sal)cnt_sal FROM emp GROUP BY deptno )
    SELECT emp.deptno, emp.ename ,empno, sal
    FROM emp , sum_sal rec1 , cnt_emp rec2
    WHERE emp.deptno = rec1.deptno
    AND rec1.deptno = rec2.deptno
    AND sal > (sal_sum/cnt_sal )

    Please let me know how to create it successfully and Oracle version is 9.2.0.7

    Thanks...
    WITH clause is not a problem to create MV, check your syntax.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width