Home » SQL & PL/SQL » SQL & PL/SQL » compile package - select V$MVREFRESH without user's rights (Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi)
compile package - select V$MVREFRESH without user's rights [message #627876] Mon, 17 November 2014 13:21 Go to next message
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 #627878 is a reply to message #627876] Mon, 17 November 2014 13:44 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
but he said that it is not good practice.


1/ Ask him why
2/ You can create the procedure/package with option AUTHID CURRENT_USER then roles will be taken into account.

Re: compile package - select V$MVREFRESH without user's rights [message #627879 is a reply to message #627878] Mon, 17 November 2014 13:57 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
https://community.oracle.com/thread/3631475
icon5.gif  Re: compile package - select V$MVREFRESH without user's rights [message #627884 is a reply to message #627878] Mon, 17 November 2014 16:17 Go to previous messageGo to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
Michel Cadot wrote on Mon, 17 November 2014 21:44

Quote:
but he said that it is not good practice.


1/ Ask him why


No answer yet.

Quote:

2/ You can create the procedure/package with option AUTHID CURRENT_USER then roles will be taken into account.


Got another error:
PLS-00157: AUTHID only allowed on schema-level programs.

Could someone explain more detailed this error and how to go on?
Thanks ahead.
Re: compile package - select V$MVREFRESH without user's rights [message #627888 is a reply to message #627884] Mon, 17 November 2014 17:16 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Since you decided we did not have to know what exactly you did, we can NOT tell you what you did wrong or how to correct it.

http://www.google.com/search?q=PLS-00157%3A+AUTHID+only+allowed+on+schema-level+programs
Re: compile package - select V$MVREFRESH without user's rights [message #627889 is a reply to message #627888] Mon, 17 November 2014 17:41 Go to previous messageGo to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
BlackSwan, Michel Cadot,

It was my mistake to put "AUTHID CURRENT_USER" in the beginning of procedure in package body.
https://community.oracle.com/message/1831912
Here was discussed earlier that "AUTHID CURRENT_USER" should be placed once in the beginning of package header.
I will report here how is it going, maybe it will be useful for someone else.

[Updated on: Mon, 17 November 2014 17:42]

Report message to a moderator

Re: compile package - select V$MVREFRESH without user's rights [message #627890 is a reply to message #627889] Mon, 17 November 2014 17:49 Go to previous messageGo to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
Unfortunately, it didn't work.
Package header compiles fine with "AUTHID CURRENT_USER" in the beginning.
But package body compiles with error "table or view does not exist" and it shows line where V$MVREFRESH is placed.
What else should I tell here you to get help?
Thanks ahead.
Re: compile package - select V$MVREFRESH without user's rights [message #627891 is a reply to message #627890] Mon, 17 November 2014 19:11 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/

do NOT tell us, SHOW us!
Re: compile package - select V$MVREFRESH without user's rights [message #627906 is a reply to message #627891] Tue, 18 November 2014 01:23 Go to previous messageGo to next message
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 #627907 is a reply to message #627906] Tue, 18 November 2014 01:48 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You must create the package in a schema that has the privilege to select on v$mvrefresh and then grant the execution privilege on this package to FLATBED_DW.
The purpose of AUTHID CURRENT_USER is to restrict the privileges of the package during its execution to those of the current user and not to have those of package owner.
Sorry, I was unclear in my previous answer.

Re: compile package - select V$MVREFRESH without user's rights [message #627908 is a reply to message #627907] Tue, 18 November 2014 01:58 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
If you do manage to convince your DBA to grant privileges, note that you will need privileges to the underlying table v_$mvrefresh of the v$mvrefresh view, so you will need:

grant select on V_$MVREFRESH to FLATBED_DW;
Re: compile package - select V$MVREFRESH without user's rights [message #627911 is a reply to message #627907] Tue, 18 November 2014 02:08 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Like:
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> CREATE OR REPLACE PACKAGE michel.PKG_TEST1 authid current_user AS
  2    procedure pr1;
  3  end;
  4  /

Package created.

SYS> show error
No errors.
SYS> CREATE OR REPLACE PACKAGE BODY michel.PKG_TEST1
  2  IS
  3    procedure  pr1
  4    as
  5    BEGIN
  6    FOR I IN (
  7               SELECT * FROM ALL_TABLES J
  8               WHERE not exists (
  9                                  SELECT 1
 10                                  FROM V$MVREFRESH O
 11                                  WHERE O.CURRMVOWNER = j.owner AND O.CURRMVNAME = j.table_name
 12                                )
 13             )
 14    LOOP
 15    RETURN; --GATHER STATS
 16    END LOOP;
 17    END;
 18  END;
 19  /

Package body created.

SYS> show error
No errors.
SYS> grant execute on michel.pkg_test1 to r;

Grant succeeded.

SYS> conn test/test
Connected.
TEST> SELECT * FROM V$MVREFRESH;

no rows selected

TEST> exec michel.PKG_TEST1.pr1

PL/SQL procedure successfully completed.

Re: compile package - select V$MVREFRESH without user's rights [message #627912 is a reply to message #627911] Tue, 18 November 2014 02:14 Go to previous message
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.

Previous Topic: fetch data based on Column
Next Topic: Deferred transaction
Goto Forum:
  


Current Time: Thu Apr 25 19:05:43 CDT 2024