2014-09-22 25 views
-1
package cpac 
as 
    STGFILE xyz_INSTANCE.FILENAME%TYPE; 
    procedure POC (cid  in xyz_instance.client_id%type, 
       stgtype in xyz_instance.stg_instance%type, 
       stgsrc in xyz_instance.stg_source%type); 
end; 

package body cpac 
as 
    procedure POC (cid  in xyz_instance.client_id%type, 
       stgtype in xyz_instance.stg_instance%type, 
       stgsrc in xyz_instance.stg_source%type 
       ) Is 
    BEGIN 
     select filename 
     into stgfile 
     from xyz_instance 
     where stg_instance = stgtype 
     and stg_source = stgsrc 
     and client_id = cid; 
    END POC; 

begin 
    POC('0123','19517','L'); 
    dbms_output.put_line(STGFILE); 
end cpac; 

SQL語句被單獨執行,程序包含SQL也執行,但只在包我得到的錯誤是:在4號線什麼是錯的這個包的聲明和定義單獨

錯誤

ORA-00900:http://docstore.mik.ua/orelly/oracle/prog2/ch16_02.htm

:無效的SQL語句,

從以下文件引用了

+0

而不是僅僅給予負面狀態什麼錯用質疑自己。 – Prashant 2014-09-22 11:51:50

回答

1

前綴包標題和正文創建與CREATE OR REPLACE

CREATE OR REPLACE package cpac 
as 
    STGFILE xyz_INSTANCE.FILENAME%TYPE; 
    procedure POC (cid  in xyz_instance.client_id%type, 
       stgtype in xyz_instance.stg_instance%type, 
       stgsrc in xyz_instance.stg_source%type); 
end; 
/

CREATE OR REPLACE package body cpac 
as 
    procedure POC (cid  in xyz_instance.client_id%type, 
       stgtype in xyz_instance.stg_instance%type, 
       stgsrc in xyz_instance.stg_source%type 
       ) Is 
    BEGIN 
     select filename 
     into stgfile 
     from xyz_instance 
     where stg_instance = stgtype 
     and stg_source = stgsrc 
     and client_id = cid; 
    END POC; 

begin 
    POC('0123','19517','L'); 
    dbms_output.put_line(STGFILE); 
end cpac; 
/

編輯:如果您沒有權限來創建一個包,那麼你就不能創建一個包。但是,您仍然可以在匿名PL/SQL塊的DECLARE部分中創建過程或函數,並在該塊的後面運行過程/函數。在下面的示例,我的登錄身份不具有權限創建存儲過程的用戶,所以我得到一個錯誤試圖創建一個:

SQL> create or replace procedure test as begin null; end; 
    2/
create or replace procedure test as begin null; end; 
* 
ERROR at line 1: 
ORA-01031: insufficient privileges 


SQL> DECLARE 
    2  stgfile xyz_instance.filename%TYPE; 
    3 
    4  procedure POC (cid  in xyz_instance.client_id%type, 
    5     stgtype in xyz_instance.stg_instance%type, 
    6     stgsrc in xyz_instance.stg_source%type 
    7     ) Is 
    8  BEGIN 
    9  select filename 
10   into stgfile 
11   from xyz_instance 
12   where stg_instance = stgtype 
13   and stg_source = stgsrc 
14   and client_id = cid; 
15  END POC; 
16 
17 begin 
18 POC('0123','19517','L'); 
19 dbms_output.put_line(STGFILE); 
20 end; 
21/
test-filename.txt 

PL/SQL procedure successfully completed. 
+0

不具有創建或替換的獨佔權限,只是想創建一個臨時包。 – Prashant 2014-09-22 11:59:12

+2

@Prashant:'臨時包'?沒有像臨時包一樣的東西。 – 2014-09-22 12:00:33

+0

所以,你的意思是我們不能有一個包,直到我們有權創建它們。 – Prashant 2014-09-22 12:01:33

相關問題