Skip to Main Content
  • Questions
  • Refresh snapshot from none snapshot owner

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Eli.

Asked: September 04, 2000 - 10:03 am UTC

Last updated: November 17, 2006 - 8:18 am UTC

Version: 8.0.6

Viewed 10K+ times! This question is

You Asked

Hi
Our database is divide to 4 areas APPLICATION, REF_MASTER, REF_READ,(snapshot of REF_MASTER) and CONNECT ,our batch process are connect to the CONNECT user.the CONNECT user have privilege to select from all snapshot and update all application tables .Some of our batch process are need to refresh some snapshot during the process.
We try to create the following stored function located in REF_READ and execute it from the CONNECT and we failed to do this by getting ORA-23401
.There was a very queer think if we add to the function the following line "SELECT USERNAME INTO USERNAME1 FROM USER_USERS" the value puts in USERNAME1 is REF_READ .so way the function failed ?
We don't want to add system privilege to our CONNECT account (we know about alter any snapshot ) Can you help us to implement this by the stored function ?

CREATE OR REPLACE FUNCTION refresh_tab
( p_tb_name VARCHAR2)
RETURN NUMBER
IS
BEGIN
DBMS_SNAPSHOT.REFRESH(p_tb_name,'C');
RETURN 0;
EXCEPTION
WHEN OTHERS THEN
RETURN sqlcode;
END;
/

Tnx


and Tom said...

I don't think this is a privileges problem but rather a name resolution issue. The ability to run dbms_snaphost has been conveyed to connect -- what connect is probably doing is not passing a fully qualified object name to refresh_tab -- hence dbms_snapshot.refresh is attempting to refresh CONNECT.snapshot_name -- which does not exist. This example shows how this works. P1 is unqualifed -- P2 has the correct schema name attached. See what happens in each case:

SQL> create snapshot foo as select * from dual;
Materialized view created.

SQL> create or replace procedure p1
2 as
3 begin
4 dbms_snapshot.refresh( 'FOO', 'C' );
5 end;
6 /

Procedure created.

SQL> create or replace procedure p2
2 as
3 begin
4 dbms_snapshot.refresh( 'OPS$TKYTE.FOO', 'C' );
5 end;
6 /

Procedure created.

SQL>
SQL> grant execute on p1 to public;

Grant succeeded.

SQL> grant execute on p2 to public;

Grant succeeded.


SQL> drop user a cascade;

User dropped.

SQL> grant create session to a identified by a;

Grant succeeded.

SQL>
SQL> connect a/a
Connected.
SQL>
SQL> exec ops$tkyte.p1
BEGIN ops$tkyte.p1; END;

*
ERROR at line 1:
ORA-23401: snapshot "A"."FOO" does not exist
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 604
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 661
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 641
ORA-06512: at "OPS$TKYTE.P1", line 4
ORA-06512: at line 1


SQL> exec ops$tkyte.p2

PL/SQL procedure successfully completed.

SQL>
SQL> connect /
Connected.

Rating

  (3 ratings)

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

Comments

Similar problem

Colin McLennan, November 17, 2006 - 7:54 am UTC

Tom,

The above was very interesting as I am having a similar problem on Oracle 10.2.0.1.0 but the error message is different from that in your example.

I have a user (User1) that owns a package (Package1) and I am trying to get this user to refresh a materialised view owned by another user (User2) by calling DBMS_MVIEW.REFRESH from Package1. The materialised view calls functions from a package (package2) owned by User2

I have granted explicit access to all of the elements to User1 including EXECUTE ANY PROCEDURE but continue to get the following error.

ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2255
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2461
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2430
ORA-06512: at "USER1.PACKAGE1", line 308
ORA-06512: at line 1

Package1 contains another procedure used to analyse tables and I can get this to run as User1 no problem.

I am starting to loose the will to live. Can you breathe new life into me and point me towards a solution.

Thanks in advance.

Colin.

Tom Kyte
November 17, 2006 - 8:18 am UTC

turn on sql_trace and see if you can see what sql statement is failing, that'll help.

else set up a script that creates usera, userb, creates the tables, creates the minimum code - eg: reproduces the issue, so we can look at it in isolation with the smallest bit of code around it.

(eg: something I can run on my computer, complete, concise)

Alter Any Materialized View

Colin McLennan, November 17, 2006 - 10:59 am UTC

Tom,

The trace file was of little help as it was showing the error as being against the V$PARAMETER table.

However, I now have the package working. The solution was to grant ALTER ANY MATERIALIZED VIEW directly to the user rather than through a role.

Thanks for your help.

Colin.

ALTER ANY MATERIALIZED VIEW

fabian wiktorowski, October 29, 2009 - 3:55 am UTC

so when you want to refresh mview in other schema there is no grant ALTER MATERIALIZED VIEW schema.mv_name but only ALTER ANY MATERIALIZED VIEW, which let refresh (and change storage and so on) to ANY mview in system. I've lost something or there is really no grant which let refresh exactly one mview in other schema (which seems to be more secure)?

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library