Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"insufficient privileges" when executing a procedure

The_Cute_DBAMay 1 2024

Experts, I would like to seek help.

SQL_ADMIN> select * from LIST_OF_PARTITIONS_TBL;

OWNER        TABLE_NAME        PARTITION_NAME
------        ----------        --------------
SCOTT        SALES_HIST        P01
SCOTT        SALES_HIST        P02
SCOTT        SALES_HIST        P03
SCOTT        SALES_HIST        P04
SCOTT        SALES_HIST        P05

I run the following PL/SQL code and it is working properly. It is able to drop the partitions.

SQL_ADMIN> 
DECLARE
    v_sql VARCHAR2(500);
BEGIN
    FOR part_list IN
    (
        SELECT owner, table_name, partition_name
        FROM LIST_OF_PARTITIONS_TBL
    )
    LOOP
        v_sql := 'ALTER TABLE ' || part_list.owner ||'.'|| part_list.table_name || ' DROP PARTITION ' || part_list.partition_name || ' UPDATE GLOBAL INDEXES';
        EXECUTE IMMEDIATE v_sql;
    END LOOP;
END;

PL/SQL procedure successfully completed.

I converted this into a package.

SQL_ADMIN>
CREATE OR REPLACE PACKAGE DROP_PARTITION_PACKAGE AS
    PROCEDURE DROP_PARTITIONS;
END DROP_PARTITION_PACKAGE;
/
CREATE OR REPLACE PACKAGE BODY DROP_PARTITION_PACKAGE AS
    PROCEDURE DROP_PARTITIONS IS
        v_sql VARCHAR2(500);
    BEGIN
        FOR part_list IN
        (
            SELECT owner, table_name, partition_name
            FROM LIST_OF_PARTITIONS_TBL
        )
        LOOP
            v_sql := 'ALTER TABLE ' || part_list.owner ||'.'|| part_list.table_name || ' DROP PARTITION ' || part_list.partition_name || ' UPDATE GLOBAL INDEXES';
            EXECUTE IMMEDIATE v_sql;
        END LOOP;
    END DROP_PARTITIONS;
END DROP_PARTITION_PACKAGE;
/

When I execute the package as the same user. SQL_ADMIN is a DBA user. I am getting the error below:

SQL_ADMIN> exec DROP_PARTITION_PACKAGE.DROP_PARTITIONS;

01031. 00000 -  "insufficient privileges"
*Cause:    An attempt was made to perform a database operation without
           the necessary privileges.
*Action:   Ask your database administrator or designated security
           administrator to grant you the necessary privileges
This post has been answered by Frank Kulash on May 1 2024
Jump to Answer
Comments
Post Details
Added on May 1 2024
3 comments
216 views