Skip to Main Content
  • Questions
  • Materialized View ON PREBUILT TABLE Error: [1]: ORA-00905: missing keyword

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, fiona.

Asked: January 29, 2016 - 9:28 pm UTC

Last updated: January 31, 2016 - 4:16 am UTC

Version: 11.2.0.2.0

Viewed 1000+ times

You Asked

Hi,

I am trying to create a materialized view which has subset of columns of decision_SCC at remote server.
I create a table (mv_decision_scc) locally that has 3 columns of the original table (decision_scc) at remote server
But once I tried to use ON PREBUILT TABLE command to create materialized view (mv_decision_scc) locally, I got error, please tell me what I am missing?

Thanks,
Fiona

--============================================================================--
-- At remote server site under data_fix schema
--============================================================================--
CREATE TABLE data_fix.decision_SCC
(
SCAC VARCHAR2(4) NOT NULL,
SCC VARCHAR2(45) NOT NULL,
VERIFICATION_DATE DATE,
AGAINST_MV_COUNT NUMBER,
APPROVER_NAME VARCHAR2(32),
FILE_SENT_DATE DATE NOT NULL,
CREATE_USER VARCHAR2(32) NOT NULL,
CREATE_DATE DATE NOT NULL,
UPDATE_USER VARCHAR2(32) NOT NULL,
UPDATE_DATE DATE NOT NULL
)
TABLESPACE data_fix_data
CACHE
NOPARALLEL
LOGGING
/
--------------------------------------------------------------------------------
-- create primary key
ALTER TABLE data_fix.decision_SCC
ADD CONSTRAINT pk_scac_scc PRIMARY KEY (SCAC, SCC, FILE_SENT_DATE)
/
--------------------------------------------------------------------------------
-- CREATE a MV log so the MV can be refreshed in dwdev
CREATE MATERIALIZED VIEW LOG ON data_fix.decision_SCC
TABLESPACE data_fix_data
WITH PRIMARY KEY
INCLUDING NEW VALUES
/

select * from data_fix.decision_SCC;

SCAC SCC VERIFICATION_DATE AGAINST_MV_COUNT APPROVER_NAME FILE_SENT_DATE CREATE_USER CREATE_DATE UPDATE_USER UPDATE_DATE
---- --------- ---------------------- ---------------- ------------- ---------------------- ----------- -------------------- ----------- --------------------
HLCU 1398890 42 10/15/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
CHNJ 13TP01706 10/23/2015 12:00:00 AM 382 James Sanders 10/15/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
HLCU 1433068 25 11/16/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
HLCU 1445649 43 10/15/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
HLCU 1457130 94 11/16/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
HLCU 1493671 32 10/15/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
CHNJ 14TL09265 10/23/2015 12:00:00 AM 57 James Sanders 10/15/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM
CHNJ 14TP01720 10/23/2015 12:00:00 AM 79 James Sanders 10/15/2015 12:00:00 AM BIN202 12/8/2015 5:13:00 PM BIN202 12/8/2015 5:13:00 PM


--============================================================================--
-- At local server site under ps_system schema
--============================================================================--
-- create a table with the same structure as in remote server with sub-set of columns
-- in order to be used for Materialized view rebuild
CREATE TABLE ps_system.mv_decision_scc AS
SELECT scac, scc, approver_name, file_sent_date FROM data_fix.decision_scc@remote_svr
/

--------------------------------------------------------------------------------
ALTER TABLE ps_system.mv_decisioned_SCC
ADD CONSTRAINT pk_scac_scc PRIMARY KEY (SCAC, SCC, FILE_SENT_DATE)
/

--------------------------------------------------------------------------------
CREATE MATERIALIZED VIEW ps_system.mv_decisioned_scc
REFRESH FORCE
ON DEMAND WITH PRIMARY KEY
ON PREBUILT TABLE WITH REDUCED PRECISION
ENABLE query rewrite
AS
SELECT scac, scc, approver_name, file_sent_date FROM data_fix.decisioned_scc@remote_svr WHERE scac = 'CMDU'
/

==> GOT ERROR [1]: ORA-00905: missing keyword

and Connor said...

The order is important. Try this

CREATE MATERIALIZED VIEW mv_decisioned_scc
ON PREBUILT TABLE WITH REDUCED PRECISION
REFRESH FORCE
ON DEMAND 
ENABLE query rewrite 



Hope this helps

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Create Materialized View Error

fiona fu, January 30, 2016 - 10:09 pm UTC

Hi Connor,
Thanks for quick response, I never realized the order is wrong, even my DBA missed that. Thank you very much!
But after I fixed the order, I got another error: ORA-01031: insufficient privileges if I have "ENABLE QUERY REWRIE" as part of the command. (MV created successfully as long as I don't have enable query rewrite command) What privileges should I have?
Thanks Fiona
------------------------------------------------------------
Error report:
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password without the appropriate privilege. This error also occurs if attempting to install a database without the necessary operating system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur if the user was granted the necessary privilege at a higher label than the current login.
*Action: Ask the database administrator to perform the operation or grant the required privileges.
For Trusted Oracle users getting this error although granted the the appropriate privilege at a higher label, ask the database administrator to regrant the privilege at the appropriate label.
Connor McDonald
January 31, 2016 - 4:16 am UTC

Take a look here

https://www.krenger.ch/blog/create-materialized-view-ora-01031/

Thats probably the most common cause.