views:

407

answers:

6

I am synchronizing tables using a stored PL/SQL procedure as part of a web application - when they hit a button it does the sync. The PL/SQL is executing as user A, but needs to disable indexes and sync a couple of tables in schema B. I can't get user A to 'alter index B.indexName unusable' despite granting it 'alter any index', and in desperation even DBA. The error is ORA-01418: specified index does not exist. This is working on another developer's sandbox but I can't figure out why. Any suggestions will be appreciated.

A: 

Are you granting the ALTER ANY INDEX privilege via a role? Or is the privilege being granted directly to user A?

Privileges granted through a role (such as DBA) are not available to definer's rights stored procedures (the default). Only privileges that are granted directly to the user are available in a definer's rights stored procedure.

Justin Cave
A: 

Does the index exist? More than once, I've lost time by not taking an error message at face value.

Dave
A: 

It is granted directly to user A as sys.

I'm not sure what "as sys" in the phrase "to user A as sys" means here. Are you saying that you ran the statement GRANT ALTER ANY INDEX TO userAlogged off, logged in, and the code still doesn't work?
Justin Cave
A: 

Yes, per this statement run as user A:

select OWNER, CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, STATUS from DBA_CONSTRAINTS
WHERE UPPER(TABLE_NAME) = 'TABLE';

OWNER    CONSTRAINT NAME   CONSTRAINT TYPE    TABLE_NAME    STATUS
B         BTABLE_FKEY             R             TABLE        ENABLED
I can't think of a better example of why new users should be able to comment on their own questions/answers (this answer in in response to a comment on another answer).
Dave
A: 

Oops, I got a little ahead of myself with the last post. The alter index is failing, and the SQL is exiting out before it deletes all from the table. Then it tries to do the inserts and fails on the integrity constraint.

A: 

I dropped the index and rebuilt it, which seems to have resolved the issue above. Now it lets me disable the index, but tells me the user has insufficient privs to alter index...rebuild online when I'm done populating the table. What privilege does user A need for that operation, if you would be so kind?

What is the error number that you get when you do the rebuild? You should just need the ALTER ANY INDEX privilege and quota on whatever tablespace you are building the index in. What is the Oracle version? Is this a standard b*-tree index?
Justin Cave