如何在oracle中将对象类型作为参数传递

时间:2016-12-21 12:40:18

标签: oracle plsql

创建的abstarct类型

create or replace TYPE    callbck      as table of callback_t;

抽象表

create or replace TYPE      CALLBACK_T                                          as object
  (
   url           varchar2(50),
   uri_key            number,
  );

以下是使用的程序,

 procedure get_callback_info
  (
     pi_clbk               callbck      := callbck      (),
    requestor varchar2,
msg varchar2)

如何将抽象对象类型的参数传递给过程get_callback_info。

我的抽象值为“http://test.com”,1345为url和uri_key

1 个答案:

答案 0 :(得分:1)

说你有这些类型和程序:

CREATE OR REPLACE TYPE CALLBACK_T AS OBJECT
(
    url VARCHAR2(50),
    uri_key NUMBER
);
CREATE OR REPLACE TYPE callbck AS TABLE OF callback_t;
CREATE OR REPLACE PROCEDURE get_callback_info(
                                              pi_clbk      IN     callbck := callbck(),
                                              requestor    IN     VARCHAR2,
                                              msg             OUT VARCHAR2
                                             ) IS
BEGIN
    /* whatever your code is */
    msg    := requestor || ' asked information on callbck with ' || pi_clbk.COUNT || ' elements';
END;

您可以使用以下内容测试您的程序:

declare
   vCallbck   callbck;
   vRequestor varchar2(20) := 'a requestor';
   vMsg       varchar2(100);
begin
    /* populate the vCallbck with 10 records */
    select CALLBACK_T ('url ' || level, level)
    bulk collect into vCallbck
    from dual
    connect by level <= 10; 
    --
    get_callback_info(vCallbck, vRequestor, vMsg);
    --
    dbms_output.put_line(vMsg);
end;
/

如果您想使用单个值进行测试,可以使用:

declare
   vCallbck   callbck;
   vRequestor varchar2(20);
   vMsg       varchar2(100);
begin
    vCallbck := callbck();
    vCallbck.extend(1);
    vCallbck(1) := CALLBACK_T('http://test.com', '1345');
    --
    get_callback_info(vCallbck, vRequestor, vMsg);
    --
    dbms_output.put_line(vMsg);
end;
/