Materialized view source columns
Hi to all.
How can I extract the all source columns of a mview? In the user_mview_keys are presented only the single source columns, but not those who are included in expression. For example:
CREATE MATERIALIZED VIEW mview1 AS
SELECT emp_no, d.dname||e.ename FROM dept d INNER JOIN emp e ON (d.deptno=e.deptno)
So, in this case, in the user_mview_keys we can see only the emp_no field but not the dname and ename fields. Is there a way to extract this information from Oracle data dictionary without parsing the materialized view query? Also, is there a way to extract all columns that are included in the WHERE clause of the materialized view query?
Any help will be appreciate!
Hey,
Try:
select * from all_tab_columns where table_name=UPPER(mv_name)Oracle treats the mv as a table.
for the other request (getting the where part) - cant think on anything but only to parse the query string.
Amiel.
Similar Messages
-
Materialized View with column based on PL/SQL function returning object
I have the following problem - it is known that materialized view wants PL/SQL functions used in it to be DETERMINISTIC. And it appears that a function which returns SDO_GEOMETRY cannot be DETERMINISTIC - I can add DETERMINISTIC modifier to my function which returns sdo_geometry based on USNG grid ID and save the package, and it compiles and runs fine with regular queries, but when it comes to materialized view (mview), the following error is thrown:
ORA-12018: following error encountered during code generation for "SCHEMA"."MVIEW_NAME"
ORA-00932: inconsistent datatypes: expected NUMBER got MDSYS.SDO_GEOMETRY
Looks like DETERMINISTIC modifier is not fully supported for object types. I have tried to use SDO_CS.FROM_USNG Oracle's function, and it appeared that this function is also non-deterministic - I cannot refresh mview with P or F on-demand refresh method (see http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14223/refresh.htm#i1008349 for a list of on-demand refresh methods). Without that function I can refresh mview with P or F flags.Hi,
Yes, the Chart Series can be based on "Function Returing SQL Query" and the "SQL" would be something like:
DECLARE
vSQL VARCHAR2(1000);
BEGIN
vSQL := 'SELECT NULL LINK, ENAME LABEL, SAL VALUE FROM EMP ORDER BY ENAME';
RETURN vSQL;
END;You should tick the "Save query without validation" underneath that. Without this, there is a validation error - the ; at the end is required to get the chart to function correctly but the validator sees this as an error.
You would need to create this separately from the report. No matter how you did it, the chart would still run a SQL statement to generate the output. If you wanted to use the "same data", then you could create a collection using the PL/SQL and base both the report and the chart on the collection instead.
Andy -
Hi all ,
I need some help on materialized view. I have to make a MV in dbms_dtm schema
I have 2 tables like below
sales and orduct
salescolumns: salesid,prodid,subid,charges
and product columns: subid and billid
sales.subid = product.subid.
i need a materialized view for this columns salesid,prodid,sum(charges),count(subid) and billid in dbms_dtm.
have to create another materialized view for below tables
order and ordertype
order columns: orderstaus,ordertype,address,ordertypeid
ordertype columns: ordername,subordername,ordertypeid
order.ordertypeid = ordertype.ordertypeid
need a materialized view for columns orderstaus,orderstaus,ordertype,address,ordername,subordername and granularity for this cloumns.
please some give me some guidens on this issue
Thanks in advanceYou should read chapters 8 & 9 of the Data Warehousing Guide:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/basicmv.htm
Just saying "you need a materialized view" doesn't provide enough information on what you need or how you plan to use it. -
How to get Materialized View to ignore unused columns in source table
When updating a column in a source table, records are generated in the corresponding materialized view log table. This happens even if the column being updated is not used in any MV that references the source table. That could be OK, so long as those updates are ignored. However they are not ignored, so when the MV is fast refreshed, I find it can take over a minute, even though no changes are required or made. Is there some way of configuring the materialized view log such that the materialized view refresh ignores these updates ?
So for examle if I have table TEST:
CREATE table test (
d_id NUMBER(10) PRIMARY KEY,
d_name VARCHAR2(100),
d_desc VARCHAR2(256)
This has an MV log MLOG$_TEST:
CREATE MATERIALIZED VIEW LOG ON TEST with rowid, sequence, primary key;
CREATE MATERIALIZED VIEW test_mv
refresh fast on demand
as
select d_id, d_name
from test;
INSERT 200,000 records
exec dbms_mview.refresh('TEST_MV','f');
update test set d_desc = upper(d_desc) ;
exec dbms_mview.refresh('TEST_MV','f'); -- This takes 37 seconds, yet no changes are required.
Oracle 10g/11gI would love to hear a positive answer to this question - I have the exact same issue :-)
In the "old" days (version 8 I think it was) populating the materialized view logs was done by Oracle auto-creating triggers on the base table. A "trick" could then make that trigger become "FOR UPDATE OF <used_column_list>". Now-a-days it has been internalized so such "triggers" are not visible and modifiable by us mere mortals.
I have not found a way to explicitly tell Oracle "only populate MV log for updates of these columns." I think the underlying reason is that the MV log potentially could be used for several different materialized views at possibly several different target databases. So to be safe that the MV log can be used for any MV created in the future - Oracle always populates MV log at any update (I think.)
One way around the problem is to migrate to STREAMS replication rather than materialized views - but it seems to me like swatting a fly with a bowling ball...
One thing to be aware of: Once the MV log has been "bloated" with a lot of unneccessary logging, you may perhaps see that all your FAST REFRESHes afterwards becomes slow - even after the one that checked all the 200000 unneccessary updates. We have seen that it can happen that Oracle decides on full table scanning the MV log when it does a fast refresh - which usually makes sense. But after a "bloat" has happened, the high water mark of the MV log is now unnaturally high, which can make the full table scan slow by scanning a lot of empty blocks.
We have a nightly job that checks each MV log if it is empty. If it is empty, it locks the MV log and locks the base table, checks for emptiness again, and truncates the MV log if it is still empty, before finally unlocking the tables. That way if an update during the day has happened to bloat the MV log, all the empty space in the MV log will be reclaimed at night.
But I hope someone can answer both you and me with a better solution ;-) -
Order by in MATERIALIZED VIEW not work successfully with first column (ID)
Dears,
I am trying to create a Materialized View as below:
CREATE MATERIALIZED VIEW HR.MV_EMP
PCTFREE 10
MAXTRANS 255
TABLESPACE users
STORAGE (
INITIAL 65536
MINEXTENTS 1
MAXEXTENTS 2147483645
BUILD IMMEDIATE
REFRESH ON DEMAND
AS
SELECT *
FROM employees
where rownum < 5000 order by employee_id desc ;But while querying the MATERIALIZED VIEW, it did not work successfully as the data did not appear in the accurate order.
I tried to create the same MATERIALIZED VIEW but order by another column (Column Date), it worked successfully and the data appeared in the accurate order.
It means that MATERIALIZED VIEW not work successfully with the first column (id).
Can you please help me in this ?
Thanks & regards,,A few pointers :
1. As has been pointed out, the ROWNUM has been incorrectly placed. ROWNUM values are assigned as rows are fetched from the source before the ORDER BY. You need to ORDER BY first (in a SubQuery) and then ROWNUM afterwards (outside the SubQuery).
2. I wonder why you want only the last 5000 EMPLOYEE_IDs. What if Employee_ID 1 is still an active employee (he is the founder, first employee and CEO ?). There could be very many "low" EMPLOYEE_IDs that are still active.
3. Logically I would expect some filter other than the ROWNUM ... ORDER BY to be used to select candidate rows. Then, an ORDER BY in the CREATE query would be unnecessary.
4. When querying the Materialized View you must explicitly ORDER BY (irrespective of whether you did or did not do an ORDER BY in the CREATE ...)
5. How do you expect to refresh the MV ? Will it always be a COMPLETE Refresh ? Remember that your "5000 employees" filter would likely exclude older employees at the next refresh. If you use some other filter, it should be consistent across all refreshs.
Hemant K Chitale -
Materialized view with selected columns on target
Hi,
I want to create a materialized view fast refresh with only selected columns on the target database like for example, i'm having a table ABC with 10 columns on the source database, i've table XYZ with 25 columns on the target database. I want to refresh only 20 columns of XYZ table with 20 columns of the ABC table.
Is this possible?
If yes, could you please share information or any weblinks or metalink notes.
Thanks,The documentation is located at http://tahiti.oracle.com.
I would give you the answer but, quite frankly, this is such a basic docs question you really need to read this yourself.
If, after reading the docs, you still have a question post the link to the document you read and explain what about the document is causing confusion.
And to be perfectly clear about my feelings ... when I taught Oracle at university ... if one of my students had asked that question my response would have been ... "Did you try it?"
And "No" would not be an acceptable answer. -
Way to add an additional column that acts as a PK in a Materialized View?
I want to create a materialized view that also has an index column. A unique number sequence assigned to each record. Is this even possible? Can a materialized view do this, and would the indexes stay the same on a refresh?
Any help would be greatly appreciated.Materialized views are copies of data or aggregations. They can be used to replicate all or part of a table, or to replicate the result of a query against multiple tables. The big advantage they have is that unlike a standard view, which can return the same data, you can index the materialized view to improve performance. These indexes will be maintained and updated during the refresh process.
Refer to Metalink document: 76673.1 or the Oracle Concepts manual for more information. -
To get list of materialized views/views using a column of a table
Hi,
I am removing sal column from table tab_emp;
i want to check whether any materialized view or view using this column by querying using data dictionary :-
if i use like condition against query column of all_mviews it is throwing error sicne it is long data type.
is there a way to search it without creating any function and use it in a query
Thanks,
Ajoystart with select * from dictionary where table_name like '%VIEW%'
to identify appropriate dictionary views.
Then read: Ask Tom &quot;Converting Longs to LOBS&quot; and Ask Tom &quot;Long to Varchar2 conversion.... &quot;
to be able to search LONG descriptions for column names.
For example:
create table check_table as
select owner,view_name,text_length,to_lob(text) text_lob from all_views
Column Name
Data Type
Nullable
Default
Primary Key
OWNER
VARCHAR2(30)
No
VIEW_NAME
VARCHAR2(30)
No
TEXT_LENGTH
NUMBER
Yes
TEXT_LOB
CLOB
Yes
select * from check_table where instr(upper(text_lob),'SAL') > 0
OWNER
VIEW_NAME
TEXT_LENGTH
TEXT_LOB
SYS
USER_ENCRYPTED_COLUMNS
147
select TABLE_NAME, COLUMN_NAME, ENCRYPTION_ALG,SALT, INTEGRITY_ALG from DBA_ENCRYPTED_COLUMNS where OWNER = SYS_CONTEXT('USERENV','CURRENT_USER')
Regards
Etbin -
Hiding a column from materialized view
Hello All,
I have created a materialized view which aggregates the monthly wise data, as we know, for refresh on commit of this view i have selected count(*) and count(col).
My problem is i don't want these columns to appear in the materialized view.
regardsIf you include the columns in the select statement that generates the materialized view they will be visible. So your choices are:
(1) don't include them in the query
(2) overley the materialized view with a plain view.
Apparently you don't like option 2, which leaves option 1. I must confess I don't understand your original post, so maybe you could explain in more depth why you have these columns you don't want. There may be some other way of achieving your aim.
Cheers, APC -
MM50 : add new column in the material view
Dear guru.
I need to add a new column of material master in the material view of MM50.
Do you have a solution (exit) in order to solve my problem ?
Thanks.> I need to add a new field in the MM50 transaction not in MM02.
Der Friend,
Pls be specific about your query. As you know MM50 is for material view extension which is a std SAP trxn to help extend the views set by standard SAP pack and if you are referring new field as a new view then it is not so easily approachable.
Shiva -
How to create list of a View's column names and source
Using SQL 2005, 2008, and 2012
How to create list of a View's column names and source. For the following example would like to @Print something like the following. Does anyone already have some code to do this? I realize there are probably some gotchas, but the views that I am looking
at to use this follows the code snippet pattern below.
DBACCT.[Account Number]
dbo.ConvertDate(DBACDT). [Boarding Date]
DBXES.DBXES
CREATE VIEW [dbo].[v_ods_DBAL]
AS
SELECT DBACCT AS [Account Number], dbo.ConvertDate(DBACDT) AS [Boarding Date], DBXES
FROM dbo.ods_DBALThe column information can be obtained from INFORMATION_SCHEMA.COLUMNS view using logic like below
SELECT c.COLUMN_NAME,c.DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = c.TABLE_NAME
AND TABLE_TYPE='VIEW')
http://technet.microsoft.com/en-us/library/ms188348.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Referencing a column of a materialized view
Hi,
I have a master table in a database A
CREATE TABLE formations (
nom_formation VARCHAR2(30) CONSTRAINT formations_nom_pk PRIMARY KEY
I have made a materialized view of that table in a remote database B
CREATE MATERIALIZED VIEW formations_mv
In the database B I also want to have this table
CREATE TABLE etudiants (
matricule NUMBER CONSTRAINT etudiants_matricule_pk PRIMARY KEY,
nom_formation VARCHAR2(30) CONSTRAINT etudiants_nom_formation_fk REFERENCES formations_mv(nom_formation)
But when I try to create the table etudiants I get an error on the foreign key that references a column in the materialized view formations_mv.
Is it impossible to reference a column in a materialized view from another table ?
Thanks.Hi,
In database B this is how I create formations_mv
CREATE MATERIALIZED VIEW formations_mv
REFRESH FAST
START WITH SYSDATE
NEXT (SYSDATE + 1 / 24 / 60)
WITH PRIMARY KEY
AS
SELECT *
FROM formations@etudiants_casa_db_link;
And in database A I create a materialized view log as
CREATE MATERIALIZED VIEW LOG ON formations
WITH PRIMARY KEY
INCLUDING NEW VALUES; -
Create materialized view with specific column sizes
Hi all,
I'm trying to create a materialized view with a specific a column size. Something like
create materialized view test_mv
refresh force on demand
as
select id,
cast(my_compound_field as nvarchar2(50))
from ( select id,
field1 || field2 my_compound_field
from my_table);But Oracle seems to ignore the cast and takes the maximum size it finds for field1 || field2 in the select query. The resulting table has a column nvarchar2(44) instead of nvarchar2(50).
This can give a problem when the view is refreshed... there could be new data that exceeds the current size, i.e. where length(field1 || field2) > 44.
How can I override the column size of a field in a materialized view?
Edit: Some additional info to clarify my case:
field1 and field2 are defined as nvarchar2(25). field1 || field2 can theoretically have a length of 50, but there is currently no data in my table that results in that length, the max is 44. I am afraid that there will be data in the future that exceeds 44, resulting in an error when the MV is refreshed!
Edited by: Pleiadian on Jan 25, 2011 2:06 PMCannot reproduce what you are saying is happening.
SQL> create table t (a nvarchar2(50), b nvarchar2(50));
Table created.
SQL> create materialized view tmv as
2 select a, b, a || b c from t;
Materialized view created.
SQL> desc tmv
Name Null? Type
A NVARCHAR2(50)
B NVARCHAR2(50)
C NVARCHAR2(100)
SQL> drop materialized view tmv;
Materialized view dropped.
SQL> create materialized view tmv as
2 select a, b, substr(a || b, 1, 10) c from t;
Materialized view created.
SQL> desc tmv
Name Null? Type
A NVARCHAR2(50)
B NVARCHAR2(50)
C NVARCHAR2(10)
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
SQL>Edited by: 3360 on Jan 25, 2011 8:10 AM
And with data
SQL> insert into t values ('3123423423143hhshgvcdcvw', 'ydgeew gdfwe dfefde wfjjjjjjj');
1 row created.
SQL> commit;
Commit complete.
SQL> desc tmv
Name Null? Type
A NVARCHAR2(50)
B NVARCHAR2(50)
C NVARCHAR2(10)
SQL> select * from tmv;
A
B C
3123423423143hhshgvcdcvw
ydgeew gdfwe dfefde wfjjjjjjj 3123423423 -
Invalid Column Name on select from materialized view?
Hey all, I have created this materialized view for my java to select from. For some reason when I try to select from it, I get invalid column name. Here is my mat view statement in its simplest form:
create materialized view mv_pgridtcevcluster_property as
select distinct clustername_ as "OBJECT_ID", CLUSTERNAME_, LICENSEMODE_
from p_gridtcevcluster p
order by clustername_;
Now when I run my select statement from jdbc:
SQL: select object_id from MV_PGRIDTCEVCLUSTER_PROPERTY
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3319)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1926)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getString(NewProxyResultSet.java:3342)
at historian.objects.mgmt.udrManagerTest.gatherObjects(udrManagerTest.java:73)
Anyone have issues with this before? It seems to throw the error sporatically, any help would be much appreciated!
Regards,
TimS
Edited by: TimS on Mar 30, 2009 1:54 PM
Nevermind, figured it out. Was using wrong column name identifier when picking values from resultset.Since you have "OBJECT_ID" in quotes, Oracle stores the column name literally and case sensitively, and the column name must be capitalized when referenced.
From a regular sql*plus window, try
select object_id from mv_pgridtcevcluster_property;
select OBJECT_ID from mv_pgridtcevcluster_property;
select "OBJECT_ID" from mv_pgridtcevcluster_property;What is the result from each of them? -
How to add new columns in materialized view
We are using Oracle 10g Release2.
We need to add new columns to a prebuilt fast refresh materialized view. We want to add 4 new columns in this table and make them part of select statement in the materialized view. We can drop the view but we cannot do complete refresh after that because the paymentsInfo table has a creation_timestamp column which is populated by before row insert trigger with systimestamp. If we did the complete refresh, all values in this column shall be changed.
CREATE MATERIALIZED VIEW paymentsInfo
ON PREBUILT TABLE
REFRESH FAST
ON DEMAND
START WITH SYSDATE
NEXT SYSDATE+5/1440
WITH PRIMARY KEY
DISABLE QUERY REWRITE AS
SELECT PAYMENT_ID,BATCH_REFERENCE, TRANSACTION_REFERENCE, NO_OF_TRANSACTIONS, DEBIT_ACC_NUM,... from payment@dblink
I want to know is there any other way to add new columns without losing any changes from the master table.
Thanks.There is no way to add new Columns to Materialized view. To add new columns, it has to be dropped and re-built again.
Extract from Oracle Documentaion:
Use the ALTER MATERIALIZED VIEW statement to modify an existing materialized view in one or more of the following ways:
To change its storage characteristics
To change its refresh method, mode, or time
To alter its structure so that it is a different type of materialized view
To enable or disable query rewrite
If you have a problem of Complete refresh, then It may be beneficial to get the backup of the MView; Drop and re-create it with modified definition; Restore the backup data leaving the new columns untouched (assuming they are to be kept as fetched from the Master site).
Maybe you are looking for
-
A resource assignment for new task during another task MS Project 2010
I would like to assing a new task during another task. Resource A is assigned Task X from May 12th - May 16th. 5 hours per day. I would like to assing new Task Y for May 14th. It will take 7 hours. So I would like to set up in MS Project 2010 as: May
-
Unity-style application swapping in openbox
I missed the W-1 binding in unity, which launches an application if it's not already running or changes focus to it if it is already running, so I decided to implement the feature in openbox. I wrote a bash script launch_or_swap, which is pretty simp
-
Dear Friends, I need your valuable suggestion to proceed. Functional Flow :- My client will have a Construction project with a budgeted hours to finish and the Manager will assign Employees to this project. they need to know all the budgted hours are
-
Freezing phone and non working keyboard
I just got my first Iphone, its the 3GS. Everything is good with it except that every once in awhile, certain parts of the screen (specifically when using the keyboard) stop working. I woud try and type a certain letter and it wont work, but the othe
-
Macbook Air hdmi display not detected
Hi, my 2011 Macbook is not detecting my hdmi display - the screen flashes blue briefly but no display is detected in system preferences or anywhere else. Any ideas? +I am using a mini display port to hdmi adapter with the thunderbolt output and I've