在存储过程中将记录用作OUT参数

时间:2017-08-31 08:03:34

标签: sql oracle stored-procedures

是否可以将定义的记录用作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;

EDIT 我试图做以下事情:

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

我在这里做错了什么?谁能解释一下? :)

3 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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;
/

答案 2 :(得分:0)

您目前获得的错误如PLS-00201和PLS-00323,是由于PACKAGE声明和包体中TYPE名称不匹配造成的。在你的包体中你写了“c_general_item”,它应该是“rec_general_item”。 试试这个,你的当前错误将得到解决----

a.aBtn span.navDescr, a.aBtn span.navDescr p {
    font-family : "Open Sans", sans-serif !important;
    font-size : $aBtnFontSize !important;
    text-align: right;
    text-align-last:left;
    font-weight:normal;
    font-variant: normal;
    font-style:normal;
    //font_size : 3rem !important;
    // line-height : 1.5; //opera ignores : MAKES THIS ERROR 
    font-stretch: normal; 
    font-size-adjust:1; 
}