2017-08-31 95 views
0

是否可以將定義的記錄用作OUT參數?在存儲過程中使用記錄作爲OUT參數

我想要做這樣的事情:

create or replace PACKAGE WEBSEARCH 
AS 

TYPE rec_general_item 
IS 
    RECORD 
    (
    item_no item_t.item_no%TYPE , 
    item_type item_t.item_type%TYPE, 
    item_state item_t.item_state%TYPE); --YB added 2014-05-01 

CURSOR columns RETURN rec_general_item; 

    PROCEDURE general_get_item(
     p_item_no IN item_t.item_no%TYPE, 
     p_item_type IN item_t.item_type%TYPE, 
     p_item OUT columns); 
END WEBSEARCH; 

編輯 我試圖做到以下幾點:

create or replace PACKAGE MIX_WEBSEARCH 
AS 

TYPE rec_general_item 
IS 
    RECORD 
    (
    item_no item_t.item_no%TYPE , 
    item_type item_t.item_type%TYPE, 
    item_state item_t.item_state%TYPE, 
    item_name item_t.item_name%TYPE, 
    prodname_no item_t.prodname_no%TYPE, 
    prod_name item_t.prod_name%TYPE, 
    prodname_no2 item_t.prodname_no2%TYPE, 
    prod_name2 item_t.prod_name2%TYPE); --YB added 2014-05-01 


    PROCEDURE general_get_item(
      p_item_no IN item_t.item_no%TYPE, 
      p_item_type IN item_t.item_type%TYPE, 
      p_item OUT rec_general_item); 
END MIX_WEBSEARCH; 

這裏是正文:

create or replace PACKAGE BODY MIX_WEBSEARCH 
AS 

    PROCEDURE general_get_item(
    p_item_no IN item_t.item_no%TYPE, 
    p_item_type IN item_t.item_type%TYPE, 
    p_item OUT c_general_item) 
IS 
BEGIN 
    OPEN p_item FOR SELECT it.item_no, it.item_type, it.item_state, it.item_name, it.prodname_no , it.prod_name, it.prodname_no2, it.prod_name2, it.prodtype_no, it.prodtype_name, it.designer_no, it.designer_name, it.req_assembly, it.unit_name, it.valid_designer, it.sale_start_date, it.sale_end_date, it.short_material_text, it.imeas_ref_imp, it.imeas_ref_met, it.valid_design_text, it.pe_no, it.hfb_no, it.hfb_name, it.pra_no, it.pra_name, it.pa_no, it.pa_name, it.rec_sales_price, it.currency_code, icst.item_no as base_item_no, ict.comclass_name 
    FROM item_t it, item_cty_spec_t icst, 
    (SELECT item_no, item_type, comclass_name FROM item_comclass_t 
    WHERE valid_from < SYSDATE AND valid_to >= SYSDATE) ict 
    WHERE it.item_no = icst.item_no_cty_spec (+) AND it.item_type = icst.item_type_cty_spec (+) 
    AND it.item_no = ict.item_no (+) AND it.item_type = ict.item_type (+) 
    AND it.item_no = p_item_no 
    AND it.item_type = p_item_type; 
END general_get_item; 

END; 

當我嘗試創建包的正文,我收到以下錯誤:

Error(3,5): PL/SQL: Item ignored 
Error(6,16): PLS-00201: identifier 'C_GENERAL_ITEM' must be declared 
Error(41,16): PLS-00323: subprogram or cursor 'GENERAL_GET_ITEM' is declared in a package specification and must be defined in the package body 

我在做什麼錯在這裏?有人可以解釋嗎? :)

+0

你混了'RECORD'和'REF CURSOR'。看到我和MT0的答案,看看有什麼不同。 –

回答

0

可以聲明一個CURSOR類型指定一個強類型的光標。

CREATE PACKAGE WEBSEARCH 
AS 
    TYPE rec_general_item IS RECORD (
    item_no item_t.item_no%TYPE , 
    item_type item_t.item_type%TYPE, 
    item_state item_t.item_state%TYPE 
); 

    TYPE general_item_cursor IS REF CURSOR RETURN rec_general_item; 

    PROCEDURE general_get_item(
    p_item_no IN item_t.item_no%TYPE, 
    p_item_type IN item_t.item_type%TYPE, 
    p_item  OUT general_item_cursor 
); 
END WEBSEARCH; 
/

CREATE PACKAGE BODY WEBSEARCH 
AS 
    PROCEDURE general_get_item(
    p_item_no IN item_t.item_no%TYPE, 
    p_item_type IN item_t.item_type%TYPE, 
    p_item  OUT general_item_cursor 
) 
    IS 
    BEGIN 
    OPEN p_item FOR 
    SELECT item_no, item_type, item_state 
    FROM item_t 
    WHERE item_no = p_item_no AND item_type = p_item_type; 
    END; 
END WEBSEARCH; 
/
1

是的,寫這樣的:

create or replace PACKAGE WEBSEARCH 
AS 

    TYPE rec_general_item 
    IS 
     RECORD 
     (
     item_no item_t.item_no%TYPE , 
     item_type item_t.item_type%TYPE, 
     item_state item_t.item_state%TYPE); 

    PROCEDURE general_get_item(
      p_item_no IN item_t.item_no%TYPE, 
      p_item_type IN item_t.item_type%TYPE, 
      p_item OUT rec_general_item); 
END; 

create or replace PACKAGE BODY WEBSEARCH 
AS 

    PROCEDURE general_get_item(
      p_item_no IN item_t.item_no%TYPE, 
      p_item_type IN item_t.item_type%TYPE, 
      p_item OUT rec_general_item) is 

    begin 
     SELECT p_item_no, p_item_type, 1 
     INTO p_item 
     FROM dual; 
    end; 

END; 
+0

@WenfriedDomscheit:我得到一個語法錯誤,而且開始陳述:「語法錯誤部分認可的規則(鐵路圖) – Bryan

+0

請參閱我的更新 –

+0

謝謝你的答案,但我仍然得到同樣的錯誤:) – Bryan

0

您當前正在越來越像PLS-00201錯誤和PLS-00323,是由於在包聲明和包體類型的名稱不匹配。在你的包體中你寫了「c_general_item」,它應該是「rec_general_item」。 試試這個,你當前的錯誤將得到解決----

create or replace PACKAGE BODY MIX_WEBSEARCH 
AS 

    PROCEDURE general_get_item(
    p_item_no IN item_t.item_no%TYPE, 
    p_item_type IN item_t.item_type%TYPE, 
    p_item OUT rec_general_item) 
IS 
BEGIN 
    OPEN p_item FOR SELECT it.item_no, it.item_type, it.item_state, it.item_name, it.prodname_no , it.prod_name, it.prodname_no2, it.prod_name2, it.prodtype_no, it.prodtype_name, it.designer_no, it.designer_name, it.req_assembly, it.unit_name, it.valid_designer, it.sale_start_date, it.sale_end_date, it.short_material_text, it.imeas_ref_imp, it.imeas_ref_met, it.valid_design_text, it.pe_no, it.hfb_no, it.hfb_name, it.pra_no, it.pra_name, it.pa_no, it.pa_name, it.rec_sales_price, it.currency_code, icst.item_no as base_item_no, ict.comclass_name 
    FROM item_t it, item_cty_spec_t icst, 
    (SELECT item_no, item_type, comclass_name FROM item_comclass_t 
    WHERE valid_from < SYSDATE AND valid_to >= SYSDATE) ict 
    WHERE it.item_no = icst.item_no_cty_spec (+) AND it.item_type = icst.item_type_cty_spec (+) 
    AND it.item_no = ict.item_no (+) AND it.item_type = ict.item_type (+) 
    AND it.item_no = p_item_no 
    AND it.item_type = p_item_type; 
END general_get_item; 

END; 
相關問題