Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:40:18+00:00 2026-06-18T02:40:18+00:00

If I create a procedure: CREATE OR REPLACE PROCEDURE SchameB.PRC_GATHER_STATS IS BEGIN SYS.DBMS_STATS.GATHER_TABLE_STATS( ‘SchName’,

  • 0

If I create a procedure:

CREATE OR REPLACE PROCEDURE SchameB.PRC_GATHER_STATS IS
BEGIN
    SYS.DBMS_STATS.GATHER_TABLE_STATS( 'SchName', 'TableName', CASCADE => TRUE);
END;

and execute it ;

EXEC SchameB.PRC_GATHER_STATS;

this gives me error ORA-20000: Unable to analyze TABLE "SchameA"."TableName", insufficient privileges or does not exist. But this works:

EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS( 'SchameA', 'TableName', CASCADE => TRUE);

The user who EXECs the procedure and the table are in different schemas.

Why am I getting an error when doing this through a procedure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:40:19+00:00Added an answer on June 18, 2026 at 2:40 am

    To gather statistics on an object in another schema you need the ANALYZE ANY system privilege. I appears that the user that runs your procedure has that privilege, but granted through a role. As the documentation says:

    All roles are disabled in any named PL/SQL block (stored procedure,
    function, or trigger) that executes with definer’s rights.

    You can either GRANT ANALYZE ANY directly to your user, or create the procedure with invoker’s rights, as:

    CREATE OR REPLACE PROCEDURE SchameB.PRC_GATHER_STATS
    AUTHID CURRENT_USER IS
    BEGIN
        SYS.DBMS_STATS.GATHER_TABLE_STATS('SchName', 'TableName', CASCADE => TRUE);
    END;
    /
    

    When you EXEC the DBMS_STATS procedure directly, it’s running as an anonymous block, and those always run with invoker’s rights – honouring roles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

create or replace procedure createtables Authid current_user as begin execute immediate 'create table newcustomer
CREATE OR REPLACE PROCEDURE proc AS CURSOR v_cursor IS BEGIN FOR obj IN v_cursor
below is the stored proc I wrote: create or replace procedure test005 as begin
I have a stored procedure create or replace procedure GETFILE(TableName in VARCHAR2) is No_Rows
CREATE OR replace PROCEDURE Hello_world2 IS BEGIN HTP.htmlopen; HTP.headopen; HTP.Title ('You knew it was
CREATE OR REPLACE PROCEDURE file_trial IS V1 VARCHAR2(32767); F1 UTL_FILE.FILE_TYPE; BEGIN F1 := UTL_FILE.FOPEN('C:\TEMP','AVI','R',256);
create or replace PROCEDURE get_txn_by_account_id( p_ACCOUNT_ID IN txn.ACCOUNT_ID%TYPE DEFAULT NULL ) IS BEGIN FOR
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
I have a stored procedure (SP) in oracle: CREATE OR REPLACE PROCEDURE SP_SEL_LOGIN_INFO (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.