2016-08-24 42 views
2

雖然試圖通過創建過程表,我面對錯誤,如Oracle過程 - AUTHID只允許在架構級別

錯誤(73,9):PLS-00157:AUTHID只允許對模式級方案

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; 
+0

如果我刪除AUTHID CURRENT_USER,其編譯成功,但運行時卻面臨權限不足的錯誤。 – Madhu

回答

1

你的程序似乎一包的一部分。在包中,您只能在包級別設置調用者權限(AUTHID CURRENT_USER)。您無法爲每個單獨的過程進行設置。

上移的調用權限的包級別:

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; 

或者創建一個全球性的程序(即在架構層面,而不是在封裝級):

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; 
+0

嗨科多,是的。我在一個包中放置了3個過程,併爲一個過程設置了AUTH ID。 正如你在上面提到的那樣,我移動了該程序來分離軟件包並將訪問級別設置爲Package,並且其工作正常。 非常感謝:-) – Madhu