creating a materialized view throws "ORA-01031: insufficient privileges" [message #681410] |
Wed, 15 July 2020 10:29  |
wtolentino
Messages: 373 Registered: March 2005
|
Senior Member |
|
|
I am attempting to create a materialized view. The based table is the same owner as the materialized view to be created. When attempted to create a materialized view it throws "ORA-01031: insufficient privileges". However, when the same query is used to create a simple view it is working. Please advise. Thank you.
SQL> select substr(owner,1,20) owner, substr(object_name,1,20) object_name,
2 substr(object_type,1,20) object_name
3 from dba_objects
4 where object_name = 'SSP_EI'
5 and owner = 'SSOWNER';
OWNER OBJECT_NAME OBJECT_NAME
-------------------- -------------------- --------------------
SSOWNER SSP_EI TABLE
SQL>
SQL> select privilege
2 from dba_sys_privs where grantee = 'SSOWNER';
PRIVILEGE
----------------------------------------
CREATE MATERIALIZED VIEW
SQL> CREATE MATERIALIZED VIEW LOG ON SSOWNER.SS_INC WITH PRIMARY KEY INCLUDING NEW VALUES;
Materialized view log created.
SQL> CREATE MATERIALIZED VIEW ssowner.ssp_ei_MV
2 NOLOGGING
3 CACHE
4 BUILD IMMEDIATE
5 REFRESH FAST ON COMMIT AS
6 SELECT EI.*
7 FROM ssowner.ssp_ei EI
8 WHERE Nvl(EI.Modify_Ts, EI.Create_Ts) > '01-JAN-19';
WHERE Nvl(EI.Modify_Ts, EI.Create_Ts) > '01-JAN-19'
*
ERROR at line 8:
ORA-01031: insufficient privileges
SQL>
|
|
|
|
|
|
Re: creating a materialized view throws "ORA-01031: insufficient privileges" [message #681415 is a reply to message #681410] |
Wed, 15 July 2020 11:30   |
 |
EdStevens
Messages: 1375 Registered: September 2013
|
Senior Member |
|
|
wtolentino wrote on Wed, 15 July 2020 10:29<snip>
SQL> CREATE MATERIALIZED VIEW ssowner.ssp_ei_MV
2 NOLOGGING
3 CACHE
4 BUILD IMMEDIATE
5 REFRESH FAST ON COMMIT AS
6 SELECT EI.*
7 FROM ssowner.ssp_ei EI
8 WHERE Nvl(EI.Modify_Ts, EI.Create_Ts) > '01-JAN-19';
WHERE Nvl(EI.Modify_Ts, EI.Create_Ts) > '01-JAN-19'
*
ERROR at line 8:
ORA-01031: insufficient privileges
SQL>
Aside from your immediate quesiton ..
If (as they should be) EI.Modify_Ts, EI.Create_Ts are DATE or TIMESTAMP, you are comparing them to a string: '01-JAN-19'. This can lead to unexpected errors. You should compare DATE to DATE and TIMESTAMP to TIMESTAMP:
WHERE Nvl(EI.Modify_Ts, EI.Create_Ts) > to_timestamp('01-JAN-19','dd-MON-rr')
But even with that, you are recreating the Y2k bug. Always, always, always use 4-digit years:
WHERE Nvl(EI.Modify_Ts, EI.Create_Ts) > to_timestamp('01-JAN-2019','dd-MON-yyyy')
|
|
|
|