compile package - select V$MVREFRESH without user's rights [message #627876] |
Mon, 17 November 2014 13:21 |
|
ecivgamer
Messages: 147 Registered: May 2011 Location: Ukraine
|
Senior Member |
|
|
Hi all,
My need is to compile package user1.pkg_1
package body should have
select column1 from V$MVREFRESH
But user1 doesn't have rights to select from V$MVREFRESH (only via user role).
I asked our dba
grant select on V$MVREFRESH to FLATBED_DW;
but he said that it is not good practice.
What other ways we can use in order to compile package?
Thanks ahead.
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
"CORE 10.2.0.3.0 Production"
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
|
|
|
|
|
|
|
|
|
|
Re: compile package - select V$MVREFRESH without user's rights [message #627906 is a reply to message #627891] |
Tue, 18 November 2014 01:23 |
|
ecivgamer
Messages: 147 Registered: May 2011 Location: Ukraine
|
Senior Member |
|
|
package header:
CREATE OR REPLACE PACKAGE "FLATBED_DW"."PKG_TEST1" authid current_user AS
procedure pr1;
end;
/
PACKAGE PKG_TEST1 compiled
package body:
CREATE OR REPLACE PACKAGE BODY "FLATBED_DW"."PKG_TEST1"
IS
procedure pr1
as
BEGIN
FOR I IN (
SELECT * FROM ALL_TABLES J
WHERE not exists (
SELECT 1
FROM V$MVREFRESH O
WHERE O.CURRMVOWNER = j.owner AND O.CURRMVNAME = j.table_name
)
)
LOOP
RETURN; --GATHER STATS
END LOOP;
END;
END;
/
PACKAGE BODY PKG_TEST1 compiled
Errors: check compiler log
SELECT * FROM USER_ERRORS WHERE NAME LIKE '%TEST1%'
NAME TYPE SEQUENCE LINE POSITION TEXT
PKG_TEST1 PACKAGE BODY 1 10 38 PL/SQL: ORA-00942: table or view does not exist
got rights via role:
SELECT *
FROM V$MVREFRESH O
SID SERIAL# CURRMVOWNER CURRMVNAME
---------- ---------- ------------------------------- -------------------------------
88 28117 FLATBED ADDRESSES
Actually, we use another table instead of all_tables, this is only for example. The purpose is to exclude rebuilding materialized views from gathering stats.
How to solve?
[Updated on: Tue, 18 November 2014 01:37] Report message to a moderator
|
|
|
|
|
|
Re: compile package - select V$MVREFRESH without user's rights [message #627912 is a reply to message #627911] |
Tue, 18 November 2014 02:14 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Or you can use EXECUTE IMMEDIATE:
SYS> drop user test cascade;
User dropped.
SYS> drop role r;
Role dropped.
SYS> create role r;
Role created.
SYS> grant select on v_$mvrefresh to r;
Grant succeeded.
SYS> grant create session, create procedure to r;
Grant succeeded.
SYS> create user test identified by test;
User created.
SYS> grant r to test;
Grant succeeded.
SYS> conn test/test
Connected.
TEST> CREATE OR REPLACE PACKAGE PKG_TEST1 authid current_user AS
2 procedure pr1;
3 end;
4 /
Package created.
TEST> show error
No errors.
TEST> CREATE OR REPLACE PACKAGE BODY PKG_TEST1
2 IS
3 procedure pr1
4 as
5 tables sys.odcivarchar2list;
6 BEGIN
7 execute immediate
8 'SELECT owner||''.''||table_name FROM ALL_TABLES J
9 WHERE not exists (
10 SELECT 1
11 FROM V$MVREFRESH O
12 WHERE O.CURRMVOWNER = j.owner AND O.CURRMVNAME = j.table_name
13 )'
14 bulk collect into tables;
15 FOR I IN tables.first..tables.last
16 LOOP
17 dbms_output.put_line (tables(i)); --GATHER STATS
18 END LOOP;
19 END;
20 END;
21 /
Package body created.
TEST> show error
No errors.
TEST> SELECT * FROM V$MVREFRESH;
no rows selected
TEST> exec PKG_TEST1.pr1
PL/SQL procedure successfully completed.
|
|
|