ORACLe PROCEDURE - AUTHID allowed only in schema level

限于喜欢 提交于 2021-02-19 04:33:59

问题


While trying to create table via procedure, I am facing error like

Error(73,9): PLS-00157: AUTHID only allowed on schema-level programs

PROCEDURE BCKUP 
AUTHID CURRENT_USER AS
statusmsg VARCHAR2(400);

BEGIN
    --Backup records
    EXECUTE IMMEDIATE 'CREATE TABLE schemaname.tabname AS SELECT pgm.* FROM XYZ pgm, IJK prf WHERE prf.col1=pgm.col1 AND prf.ID IN(SELECT ID FROM TAB2)';
    COMMIT;

EXCEPTION WHEN OTHERS THEN
    statusmsg :='SQL ERRROR CODE ' || SQLCODE|| ' -ERROR- ' ||SQLERRM;
    dbms_output.put_line('ERROR : ' || statusmsg);
END BCKUP;

回答1:


Your procedure seems to part of a package. In a package, you can only set invoker rights (AUTHID CURRENT_USER) at the package level. You cannot set it for each individual procedure.

Either move the invoker rights to the package level:

CREATE OR REPLACE PACKAGE pkg
AUTHID CURRENT_USER
AS

    PROCEDURE BCKUP;

    -- more types, procedures and functions

END pkg;


CREATE OR REPLACE PACKAGE BODY pkg
AS

    PROCEDURE BCKUP 

    statusmsg VARCHAR2(400);

    BEGIN
        --Backup records
        EXECUTE IMMEDIATE 'CREATE TABLE schemaname.tabname AS SELECT pgm.* FROM XYZ pgm, IJK prf WHERE prf.col1=pgm.col1 AND prf.ID IN(SELECT ID FROM TAB2)';
        COMMIT;

    EXCEPTION WHEN OTHERS THEN
        statusmsg :='SQL ERRROR CODE ' || SQLCODE|| ' -ERROR- ' ||SQLERRM;
        dbms_output.put_line('ERROR : ' || statusmsg);
    END BCKUP;

END pkg;

Or create a global procedure (i.e. at schema level and not at package level):

CREATE OR REPLACE PROCEDURE BCKUP 
AUTHID CURRENT_USER AS
statusmsg VARCHAR2(400);

BEGIN
    --Backup records
    EXECUTE IMMEDIATE 'CREATE TABLE schemaname.tabname AS SELECT pgm.* FROM XYZ pgm, IJK prf WHERE prf.col1=pgm.col1 AND prf.ID IN(SELECT ID FROM TAB2)';
    COMMIT;

EXCEPTION WHEN OTHERS THEN
    statusmsg :='SQL ERRROR CODE ' || SQLCODE|| ' -ERROR- ' ||SQLERRM;
    dbms_output.put_line('ERROR : ' || statusmsg);
END BCKUP;


来源:https://stackoverflow.com/questions/39113926/oracle-procedure-authid-allowed-only-in-schema-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!