Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Materialized Views

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

REFRESHING MATERIALIZED VIEW - https://uhesse.

com/2009/07/08/brief-introduction-
into-materialized-views/

exec dbms_mview.refresh(list=>'MV1',method=>'C')
select mview_name,staleness from user_mviews; [ to check status of the mview -
if the basetable definition changed ]
exec dbms_mview.refresh('MV1','F')
select MVIEW_NAME,LAST_REFRESH_TYPE,LAST_REFRESH_DATE from user_mviews;

DBA_DB_LINKS Lists all database links in the database.


ALL_DB_LINKS Lists all database links accessible to the connected user.
USER_DB_LINKS Lists all database links owned by the connected user.

select OWNER,DB_LINK,USERNAME from DBA_DB_LINKS;

OWNER DBLINK OWNER HOST


SERVICE PWH SERVICE (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = 153.110.197.138)(PORT = 1530)) (CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = P001PWH))) 28-APR-16
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------->>
Database Link in RBST2 Environment at Source:

SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF
TRIMSPOOL ON

BEGIN
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform,
'SQLTERMINATOR', true);
DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY',
true);
END;
/

SELECT DBMS_METADATA.get_ddl ('DB_LINK','PWH','SERVICE') FROM dba_db_links;


"
CREATE DATABASE LINK "PWH"
CONNECT TO "SERVICE" IDENTIFIED BY VALUES ':1'
USING '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 153.110.197.138)(PORT =
1530)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = P001PWH)))'"

WHERE owner = DECODE(UPPER('&1'), 'ALL', owner, UPPER('&1'));

SET PAGESIZE 14 LINESIZE 1000 FEEDBACK ON VERIFY ON

DROPPING Database Link/MView:

DROP MATERIALIZED VIEW sales_by_month_by_state;


DROP PUBLIC DATABASE LINK remote;

select OWNER,OBJECT_NAME,OBJECT_TYPE from dba_objects where


OBJECT_NAME='MGMT_ECM_MD_ALL_TBL_COLUMNS';

SYSMAN MGMT_ECM_MD_ALL_TBL_COLUMNS MATERIALIZED VIEW


SYSMAN MGMT_ECM_MD_ALL_TBL_COLUMNS TABLE

AVTALE MATVIEW_FRE MATERIALIZED VIEW


AVTALE MATVIEW_FRE TABLE

-----------------------------------------------------------------------------------
------------------------------------------------------------------------------->>
MATERIALIZED VIEW in Oracle: [RBST2]
SYS@dat-efs-r-c06-scan:1530/rbs_r_t2 SQL>select OWNER,MVIEW_NAME from all_mviews;

OWNER--- MVIEW_NAME--
SYSMAN MGMT_ECM_MD_ALL_TBL_COLUMNS
AVTALE MATVIEW_FRE

Getting List of MATERIALIZED View:


select * from all_mviews;
or
select * from dba_mviews;
or
select * from all_objects where OBJECT_TYPE='MATERIALIZED VIEW';

Getting Metadata of MATERIALIZED VIEW :


===================================================================================
===========================================================================>>
select * from all_mviews;
OWNER NOT NULL VARCHAR2(30)
MVIEW_NAME NOT NULL VARCHAR2(30)
CONTAINER_NAME NOT NULL VARCHAR2(30)
QUERY LONG
QUERY_LEN NUMBER(38)
UPDATABLE VARCHAR2(1)
UPDATE_LOG VARCHAR2(30)
MASTER_ROLLBACK_SEG VARCHAR2(30)
MASTER_LINK VARCHAR2(128)
REWRITE_ENABLED VARCHAR2(1)
REWRITE_CAPABILITY VARCHAR2(9)
REFRESH_MODE VARCHAR2(6)
REFRESH_METHOD VARCHAR2(8)
BUILD_MODE VARCHAR2(9)
FAST_REFRESHABLE VARCHAR2(18)
LAST_REFRESH_TYPE VARCHAR2(8)
LAST_REFRESH_DATE DATE
STALENESS VARCHAR2(19)
AFTER_FAST_REFRESH VARCHAR2(19)
UNKNOWN_PREBUILT VARCHAR2(1)
UNKNOWN_PLSQL_FUNC VARCHAR2(1)
UNKNOWN_EXTERNAL_TABLE VARCHAR2(1)
UNKNOWN_CONSIDER_FRESH VARCHAR2(1)
UNKNOWN_IMPORT VARCHAR2(1)
UNKNOWN_TRUSTED_FD VARCHAR2(1)
COMPILE_STATE VARCHAR2(19)
USE_NO_INDEX VARCHAR2(1)
STALE_SINCE DATE
NUM_PCT_TABLES NUMBER
NUM_FRESH_PCT_REGIONS NUMBER
NUM_STALE_PCT_REGIONS NUMBER

SYSMAN MGMT_ECM_MD_ALL_TBL_COLUMNS
MGMT_ECM_MD_ALL_TBL_COLUMNS SELECT c.METADATA_ID,
1179 N
N TEXTMATCH DEMAND FORCE DEFERRED NO COMPLETE 05-JUN-12 FRESH
NA N N N N N N VALID N 0
m.TARGET_TYPE,

m.SNAPSHOT_TYPE,

t.name as TABLE_NAME,

c.NAME,

c.UI_NAME,

c.TYPE, c.TYPE_FORMAT,

c.UI_ON, c.COMPARE_ON, c.COMPARE_UI_ON, c.HISTORY_ON, c.HISTORY_UI_ON,

c.IS_KEY, c.IS_CONTEXT, c.IS_SUMMARY,

c.IS_CHILD_LINK, c.LINK_COLUMN_NAME,

rank() over (partition by c.metadata_id, t.name

order by anc.tbl_order asc, c.col_order asc) as COL_ORDER,

c.table_name as SOURCE_TABLE_NAME

FROM

mgmt_ecm_snapshot_metadata m,

mgmt_ecm_snapshot_md_tables t,

mgmt_ecm_snapshot_md_tables anc,

mgmt_ecm_snapshot_md_columns c

WHERE

(anc.name, anc.metadata_id) in
(SELECT anc_t.name, anc_t.metadata_id

FROM mgmt_ecm_snapshot_md_tables anc_t

START WITH anc_t.name = t.name

AND anc_t.metadata_id = t.metadata_id

CONNECT BY anc_t.name = PRIOR anc_t.parent_table_name

AND anc_t.metadata_id = PRIOR anc_t.metadata_id)

AND c.metadata_id = anc.metadata_id

AND c.table_name = anc.name

AND c.metadata_id = m.metadata_id

AND m.kind = 'P'

AND ((c.is_key = 'Y') OR (anc.name = t.name))

AVTALE MATVIEW_FRE MATVIEW_FRE


SELECT AJORADATO,
331 N
N NONE COMMIT FAST IMMEDIATE DIRLOAD_DML FAST 18-AUG-17 UNKNOWN
NA N Y N N N N VALID N 29-SEP-17 0

BRANDNAME,

CAMPAIGNTEXT,

CUSTREFPOS,

FU_ID,

FUSP_ID,

FUSP_ID_TYPE,

OPPRORADATO,
RULENUMBER,

AVTALE.REGEXP_TRANSFORM(ACCNUMRULE) as ACCNUMRULE ,

AVTALE.REGEXP_TRANSFORM(INVOICENUMRULE) as INVOICENUMRULE

FROM AVTALE.FRE

WHERE FUSP_ID <> '080'

===================================================================================
===================================================================================
=================>>

https://www.toadworld.com/platforms/oracle/w/wiki/4935.script-to-create-ddl-for-
existing-materialized-view-for-fast-refresh

REM LOCATION: Object Management\Materialized Views and Materialized View Logs


REM FUNCTION: Get Oracle to create the DDL for your fast refresh Mview For you.
REM TESTED ON: 10.2.0.3, 11.1.0.6
REM PLATFORM: non-specific
REM REQUIRES: dbms_metadata, dbms_advisor
REM
REM This is a part of the Knowledge Xpert for Oracle Administration library.
REM Copyright (C) 2008 Quest Software
REM All rights reserved.
REM
REM Note: The result of this code will be create mview log and create mview
REM statements that you can use to re-create your exiting mviews or create
REM new mviews as fast refreshable.
REM ******************** Knowledge Xpert for Oracle Administration
********************
SET serveroutput on
SET feedback off
UNDEF ENTER_MVIEW_OWNER
UNDEF ENTER_MVIEW_NAME

DECLARE
v_task_name VARCHAR2 (100);
v_mview_owner VARCHAR2 (30) := UPPER ('&&ENTER_MVIEW_OWNER');
v_mview_name VARCHAR2 (30) := UPPER ('&&ENTER_MVIEW_NAME');
v_sql VARCHAR2 (4000);
BEGIN
-- get mview text from data dictionary
SELECT DBMS_METADATA.get_ddl ('MATERIALIZED_VIEW', mview_name, owner)
INTO v_sql
FROM dba_mviews
WHERE owner = v_mview_owner AND mview_name = v_mview_name;

DBMS_OUTPUT.put_line ('MVIEW SQL Is: ' || v_sql);


DBMS_ADVISOR.tune_mview (v_task_name, v_sql);
DBMS_OUTPUT.put_line (CHR (13));
DBMS_OUTPUT.put_line
('SQL Commands to create fast refresh Materialized View');
DBMS_OUTPUT.put_line (CHR (13));
DBMS_OUTPUT.put_line ('Original Mview Code: ');
DBMS_OUTPUT.put_line (v_sql);
DBMS_OUTPUT.put_line (CHR (13));

FOR tt IN (SELECT action_id, STATEMENT


FROM dba_tune_mview
WHERE script_type = 'IMPLEMENTATION'
AND task_name = v_task_name
ORDER BY action_id)
LOOP
DBMS_OUTPUT.put_line ('Statement Order Number: ' || tt.action_id);
DBMS_OUTPUT.put_line ('Statement ID : ' || tt.STATEMENT);
DBMS_OUTPUT.put_line (CHR (13));
END LOOP;
-- You can also use the following query to look at the dba_tune_mview view:
-- select statement from dba_tune_mview
-- where script_type='IMPLEMENTATION'
-- and task_name=v_task_name
-- order by action_id;
END;

===================================================================================
=======================================================================>>>>>>>
MVIEW SQL Is:

MATVIEW_FRE :

CREATE MATERIALIZED VIEW "AVTALE"."MATVIEW_FRE" ("AJORADATO", "BRANDNAME",


"CAMPAIGNTEXT", "CUSTREFPOS", "FU_ID", "FUSP_ID", "FUSP_ID_TYPE", "OPPRORADATO",
"RULENUMBER", "ACCNUMRULE", "INVOICENUMRULE")
ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "DATA_AVTALE"
BUILD IMMEDIATE
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "DATA_AVTALE"
REFRESH FAST ON COMMIT
WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
AS SELECT AJORADATO,
BRANDNAME,
CAMPAIGNTEXT,
CUSTREFPOS,
FU_ID,
FUSP_ID,
FUSP_ID_TYPE,
OPPRORADATO,
RULENUMBER,
AVTALE.REGEXP_TRANSFORM(ACCNUMRULE) as ACCNUMRULE ,
AVTALE.REGEXP_TRANSFORM(INVOICENUMRULE) as INVOICENUMRULE
FROM AVTALE.FRE
WHERE FUSP_ID <> '080'

===================================================================================
===========================================================================>
MVIEW SQL Is:

MGMT_ECM_MD_ALL_TBL_COLUMNS

CREATE MATERIALIZED VIEW "SYSMAN"."MGMT_ECM_MD_ALL_TBL_COLUMNS" ("METADATA_ID",


"TARGET_TYPE", "SNAPSHOT_TYPE", "TABLE_NAME", "NAME", "UI_NAME", "TYPE",
"TYPE_FORMAT", "UI_ON", "COMPARE_ON", "COMPARE_UI_ON", "HISTORY_ON",
"HISTORY_UI_ON", "IS_KEY", "IS_CONTEXT", "IS_SUMMARY", "IS_CHILD_LINK",
"LINK_COLUMN_NAME", "COL_ORDER", "SOURCE_TABLE_NAME")
ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX"
BUILD DEFERRED
USING INDEX
REFRESH FORCE ON DEMAND
USING DEFAULT LOCAL ROLLBACK SEGMENT
USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
AS SELECT c.METADATA_ID,
m.TARGET_TYPE,
m.SNAPSHOT_TYPE,
t.name as TABLE_NAME,
c.NAME,
c.UI_NAME,
c.TYPE, c.TYPE_FORMAT,
c.UI_ON, c.COMPARE_ON, c.COMPARE_UI_ON, c.HISTORY_ON, c.HISTORY_UI_ON,
c.IS_KEY, c.IS_CONTEXT, c.IS_SUMMARY,
c.IS_CHILD_LINK, c.LINK_COLUMN_NAME,
rank() over (partition by c.metadata_id, t.name
order by anc.tbl_order asc, c.col_order asc) as COL_ORDER,
c.table_name as SOURCE_TABLE_NAME
FROM
mgmt_ecm_snapshot_metadata m,
mgmt_ecm_snapshot_md_tables t,
mgmt_ecm_snapshot_md_tables anc,
mgmt_ecm_snapshot_md_columns c
WHERE
(anc.name, anc.metadata_id) in
(SELECT anc_t.name, anc_t.metadata_id
FROM mgmt_ecm_snapshot_md_tables anc_t
START WITH anc_t.name = t.name
AND anc_t.metadata_id = t.metadata_id
CONNECT BY anc_t.name = PRIOR anc_t.parent_table_name
AND anc_t.metadata_id = PRIOR anc_t.metadata_id)
AND c.metadata_id = anc.metadata_id
AND c.table_name = anc.name
AND c.metadata_id = m.metadata_id
AND m.kind = 'P'
AND ((c.is_key = 'Y') OR (anc.name = t.name))

===================================================================================
============================================================================>>

You might also like