2017-08-30 108 views
0

我已經在Oracle中創建了下面的包創建一個存儲過程:在包甲骨文

CREATE OR REPLACE PACKAGE PackageName AS 

TYPE 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, 
    prodtype_no item_t.prodtype_no%TYPE, 
    prodtype_name item_t.prodtype_name%TYPE, 
    designer_no item_t.designer_no%TYPE, 
    designer_name item_t.designer_name%TYPE, 
    req_assembly item_t.req_assembly%TYPE, 
    unit_name item_t.unit_name%TYPE, 
    valid_designer item_t.valid_designer%TYPE, 
    sale_start_date item_t.sale_start_date%TYPE, 
    sale_end_date item_t.sale_end_date%TYPE, 
    short_material_text item_t.short_material_text%TYPE, 
    imeas_ref_imp item_t.imeas_ref_imp%TYPE, 
    imeas_ref_met item_t.imeas_ref_met%TYPE, 
    valid_design_text item_t.valid_design_text%TYPE, 
    pe_no item_t.pe_no%TYPE, 
    hfb_no item_t.hfb_no%TYPE, 
    hfb_name item_t.hfb_name%TYPE, 
    pra_no item_t.pra_no%TYPE, 
    pra_name item_t.pra_name%TYPE, 
    pa_no item_t.pa_no%TYPE, 
    pa_name item_t.pa_name%TYPE, 
    rec_sales_price item_t.rec_sales_price%TYPE, 
    currency_code item_t.currency_code%TYPE, 
    base_item_no item_cty_spec_t.item_no%TYPE, --YB added 2014-05-01 
    comclass_name item_comclass_t.comclass_name%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 general_item); 


END PackageName; 

,這裏是我的過程,我試着去創造:

create or replace PACKAGE BODY PackageName 
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) 
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 PackageName; 

當我嘗試創建過程中,我得到以下信息:

錯誤(8,3):PL/SQL:SQL語句忽略錯誤(8,8):PLS-00456:項目 'P_ITEM'不是遊標

在Oracle中使用包和過程進行新操作。誰能幫我這個?

+0

錯誤消息很明顯:'general_item'是**類型**。你不能打開一個類型也不能爲該類型賦值。請解釋你用tis代碼解決什麼問題? – krokodilko

+0

如果我不得不猜測你想要做什麼,你想從select語句的值加載到記錄類型中。如果是這種情況,請查看PL/SQL中的'INTO'子句。 –

回答

0

無法打開遊標TYPERECORD。它必須是CURSOR類型。因此,只需更換這整個聲明 -

TYPE general_item 
IS 
RECORD 
    (
    item_no item_t.item_no%TYPE , 
    item_type item_t.item_type%TYPE, 
    item_state i 
    ..... 


    ..... 
    comclass_name item_comclass_t.comclass_name%TYPE); 

TYPE general_item IS REF CURSOR; 
0

無法獲取光標(可能是多行)爲TYPE。沒有表格結構很難想象這個字段是什麼類型。 無論如何easiser的方法是使用item_t%ROWTYPE,如果遊標返回一行。