table和record 型別用作引數

yellowlee發表於2009-08-22

pub上有個兄弟發過帖子問過這個,舉例一個用作in引數的:

create table t_test_recod(id number ,name varchar2(10));

insert into t_test_recod select 1,'name1' from dual;

create or replace package pac_test is
  type type_record is record(
    id   t_test_recod.id%type,
    name t_test_recod.name%type);
  type type_table is table of type_record index by binary_integer;
 
  procedure pro_test_record(rec in type_record);
  procedure pro_test_record_test;
 
  procedure pro_test_table(tab in type_table);
  procedure pro_test_table_test;
 
end pac_test;
create or replace package body pac_test is
  procedure pro_test_record(rec in type_record) is
    records type_record;
  begin
    select id, name into records from t_test_recod where id = rec.id;
    dbms_output.put_line(records.id || records.name);
  end pro_test_record;

  procedure pro_test_record_test is
    rec type_record;
  begin
    rec.id := 1;
    rec.name := 'name1';
    pro_test_record(rec);
  end pro_test_record_test;
 
  procedure pro_test_table(tab in type_table) is
  v_tab       type_table;
  begin
  v_tab := tab;
  select id, name into v_tab(1) from t_test_recod where id = v_tab(1).id;
  dbms_output.put_line(v_tab(1).id || v_tab(1).name);
  end pro_test_table;
 
  procedure pro_test_table_test is
  v_tab      type_table;
  begin
  v_tab(1).id := 1;
  v_tab(1).name := 'name1';
  pro_test_table(v_tab);
  end pro_test_table_test;
 
end pac_test;

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16179598/viewspace-612976/,如需轉載,請註明出處,否則將追究法律責任。

相關文章