Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

"execute DBMS_MVIEW.REFRESH"... Need to understand it in detail

Posted on 2009-03-28
11
Medium Priority
?
3,175 Views
Last Modified: 2013-12-18
I need to understand what this code is doing

execute DBMS_MVIEW.REFRESH('briir.cust_product');

seems like it's excuting oracles view... I need to know what exactly view/triger is doing...

someone has been using this code (via Toad for oracle) to refresh database (unfortunately he left)...
I am a new bee and would require step by step assistance...

Thanks again for your assistance
0
Comment
Question by:tparvaiz
  • 6
  • 5
11 Comments
 
LVL 25

Expert Comment

by:lwadwell
ID: 24011627
Hi tparvaiz,

Oracle has views ... where a view is a stored SQL that creates the output by running the SQL when it is accessed in another SQL etc.  Hence they are dynamic ... as the underlying data changes so does the view.

It also has Materialized views ...(in simple terms)  these are are also stored SQL's that are permanent in that they act like tables.  These are static and do not change until refreshed.  So even if the unlying tables change, the materialised view remains the same until refreshed.

That execute statement you showed is an on demand refresh of a materialized view.

For some documentation, see http://download.oracle.com/docs/cd/B10501_01/server.920/a96567/repmview.htm

lwadwell
0
 

Author Comment

by:tparvaiz
ID: 24011636
how can I find out what this view is doing (which tables are joined on what fields)...

Thanks
0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24011654
In TOAD in the shcema browser you may find it under "snapshots" I think (instead of views) ... depends on your version.  

You can check out the sys table ALL_MVIEWS e.g. SELECT * FROM all_mviews WHERE mview_name = upper('briir.cust_product').
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 25

Expert Comment

by:lwadwell
ID: 24011658
sorry, quick correction

SELECT * FROM all_mviews WHERE owner = upper('briir') AND mview_name = upper('cust_product')
0
 

Author Comment

by:tparvaiz
ID: 24011688
Sure... I'll give it a try and will let you know my findings...

Another quick one... Before refreshing this view... How can I create a copy of it and save it as a table

would this work...?

create table temp_copy
as
select * from 'briir.cust_product';

Thanks
0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24011721
yes ... it would work (as long as you don't quote the mview).
0
 

Author Comment

by:tparvaiz
ID: 24011735
I am able to read the view (though not through toad)

how can I modify the view... want to change year 2008 to 2009...

Thanks again for your assistance... I think we are getting somewhere now...
0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24011769
I am surprised you cannot see it through TOAD. What version are you using?

Is the year 2008 hard-coded?  To change the definition, i.e. the SQL, you will need to DROP MATERIALIZED VIEW and recreate it via a CREATE MATERIALIZED VIEW.  I don't believe you can ALTER the SQL.
0
 

Author Comment

by:tparvaiz
ID: 24011825
I am using toad version 9.1... I can view "MATERIALIZED VIEW" (by going through schema browser) and can open the script in the editor too... But when I am saving, it saves as local file (on my PC)... Is there a way to save it on the server...

Script reads something like this...




DROP MATERIALIZED VIEW briir.cust_product;
CREATE MATERIALIZED VIEW BRIIR.CUST_PRODUCT
TABLESPACE BI_DATA
PCTUSED    0
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          80K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOCACHE
LOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
WITH PRIMARY KEY
ENABLE QUERY REWRITE
AS
/* Formatted on 2009/03/29 02:44 (Formatter Plus v4.8.8) */
SELECT   (CASE
             WHEN seg_sales = 'ABC'
                THEN 'ABC'
             ELSE 'OTHER'
          END
         ) AS mkt_segment,
         parent_name, product_portfolio, product_description,
         ROUND (SUM (m_01jan)) AS jan, ROUND (SUM (m_02feb)) AS feb,
         ROUND (SUM (m_03mar)) AS mar, ROUND (SUM (m_04apr)) AS apr,
         ROUND (SUM (m_05may)) AS may, ROUND (SUM (m_06jun)) AS jun,
         ROUND (SUM (m_07jul)) AS jul, ROUND (SUM (m_08aug)) AS aug,
         ROUND (SUM (m_09sep)) AS sep, ROUND (SUM (m_10oct)) AS oct,
         ROUND (SUM (m_11nov)) AS nov, ROUND (SUM (m_12dec)) AS DEC,
         ROUND (SUM (  m_01jan
                     + m_02feb
                     + m_03mar
                     + m_04apr
                     + m_05may
                     + m_06jun
                     + m_07jul
                     + m_08aug
                     + m_09sep
                     + m_10oct
                     + m_11nov
                     + m_12dec
                    )
               ) AS ytd
    FROM brr.t_brr
   WHERE data_type = 'Actual' AND data_year = 2009 AND profitability = 'TRUE'
GROUP BY (CASE
             WHEN seg_sales = 'ABC'
                THEN 'ABC'
             ELSE 'OTHER'
          END
         ),
         parent_name,
         product_portfolio,
         product_description;

COMMENT ON MATERIALIZED VIEW BRIIR.CUST_PRODUCT IS 'snapshot table for snapshot BRIIR.CUST_PRODUCT';

CREATE BITMAP INDEX BRR.IDX_MV_SEGCUSTPROD_SEG ON BRIIR.CUST_PRODUCT
(MKT_SEGMENT)
LOGGING
TABLESPACE BI_INDEX
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          80K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOPARALLEL;

CREATE INDEX BRR.IDX_MV_SEGCUSTPROD_PARENT ON BRIIR.CUST_PRODUCT
(PARENT_NAME)
LOGGING
TABLESPACE BI_INDEX
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          80K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOPARALLEL;

CREATE BITMAP INDEX BRR.IDX_MV_SEGCUSTPROD_PORTF ON BRIIR.CUST_PRODUCT
(PRODUCT_PORTFOLIO)
LOGGING
TABLESPACE BI_INDEX
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          80K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOPARALLEL;

CREATE BITMAP INDEX BRR.IDX_MV_SEGCUSTPROD_PROD ON BRIIR.CUST_PRODUCT
(PRODUCT_DESCRIPTION)
LOGGING
TABLESPACE BI_INDEX
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
            INITIAL          80K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
NOPARALLEL;


how to create this view... any suggestion...?
0
 
LVL 25

Accepted Solution

by:
lwadwell earned 200 total points
ID: 24011917
TOAD works on the PC and saves files only on the visisble PC filesystem.

What you have is a complete script.  It should be able to be run 'as is' in TOAD, SQLplus etc.

A quick run through is that it will delete the MV (DROP) and then recreate it (CREATE MATERIALIZED VIEW) and then add 4 indexes (CREATE [BITMAP] INDEX).

The 'important' part of the MV is the SELECT statement ... I would not recreate the view without testing the SQL first.
0
 

Author Closing Comment

by:tparvaiz
ID: 31563982
Thanks a lot for your assistance...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question