2015-07-21 31 views
-1
SET serveroutput ON; 
DECLARE 
PROCEDURE get_csa_type(pin_CVC_object_id  IN NUMBER 
         ,posa_csa_type   OUT common.types.string 
         ,pona_permanent_csa OUT common.types.string  
        ) 
IS 

    lc_csa_type common.types.string := 'SELECT UNIQUE csa.csa_type,csa.permanent_csa '|| 
    'FROM ems.ibo_sm_cvc_rfs cvc' || 
    ',ems.ibo_nbn_csa csa ' || 
    'WHERE cvc.object_id = :1 ' || 
    'AND csa.csa_id = cvc.csa_id'; 
BEGIN  


    EXECUTE IMMEDIATE lc_csa_type BULK COLLECT INTO posa_csa_type, pona_permanent_csa 
    USING pin_CVC_object_id; 

END; 
ls_csa_type common.types.string; 
ls_permanent_csa common.types.string; 
BEGIN 
get_csa_type(pin_CVC_object_id => 8581213 
      ,posa_csa_type => ls_csa_type 
      ,pona_permanent_csa => ls_permanent_csa); 
dbms_output.put_line(ls_csa_type || ls_permanent_csa); 

END; 

我可以聲明並在pl-sql塊中調用上面的過程。當我嘗試運行此我得到幾個錯誤...聲明並在PL-SQL塊中使用PROCEDURE

Encountered the symbol "LS_CSA_TYPE" when expecting one of the following:

begin function pragma procedure

Encountered the symbol "DBMS_OUTPUT" when expecting one of the following:

:= . (% ;

+1

是的,你可以。請開始來自[PL/SQL概述](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/overview.htm#LNPLS141)。它解釋了一個語法錯誤。 – user272735

+0

謝謝,但我在這裏找不到聲明過程並在塊中執行它 –

回答

2

您需要在開始時移動的變量聲明,子過程之前。下面的代碼可以用於我:

DECLARE 
    ls_csa_type varchar2(4000); 
    ls_permanent_csa varchar2(4000); 

    PROCEDURE get_csa_type(pin_CVC_object_id  IN NUMBER 
         ,posa_csa_type   OUT varchar2 
         ,pona_permanent_csa OUT varchar2) IS 
     lc_csa_type varchar2(4000) := 'SELECT dummy, dummy from dual where 1 = :1 '; 
    BEGIN  
     EXECUTE IMMEDIATE lc_csa_type 
     INTO posa_csa_type, pona_permanent_csa 
     USING pin_CVC_object_id; 
    END get_csa_type; 

BEGIN 
    get_csa_type(pin_CVC_object_id => 1 
       ,posa_csa_type => ls_csa_type 
       ,pona_permanent_csa => ls_permanent_csa); 
    dbms_output.put_line(ls_csa_type || ls_permanent_csa); 
END; 
+0

嗯,這是真正的anwser,謝謝 –

1

在該行

END get_csa_type; 

刪除get_csa_type:

END; 

而且此行後,你必須有一個分隔符;

get_csa_type(pin_CVC_object_id => 8581213 
      ,posa_csa_type => ls_csa_type 
      ,pona_permanent_csa => ls_permanent_csa); 
+0

更新了問題中的代碼,仍然在期待以下某項時遇到'遇到符號「LS_CSA_TYPE」:開始函數編譯程序' –

3

對不起,但我認爲你跳過「申報」在執行塊:

**declare** 
ls_csa_type common.types.string; 
ls_permanent_csa common.types.string; 
BEGIN 
get_csa_type(pin_CVC_object_id => 8581213 
      ,posa_csa_type => ls_csa_type 
      ,pona_permanent_csa => ls_permanent_csa) 
dbms_output.put_line(ls_csa_type || ls_permanent_csa); 

END; 
+0

我已經在我的問題代碼的第二行聲明瞭,如果我在聲明2個變量之前會聲明這個錯誤:'遇到符號'DECLARE'' –

+0

嗯,你確定嗎?添加第二個聲明,但仍然得到相同的錯誤,根據您的意見更新了問題 –