Friday, September 11, 2009

RECORD TYPE

SQL> create type item_rec is object(item varchar2(20),desc_ varchar2(30));
2 /

Type created

SQL> create type item_list is type of item_rec;
2 /

Warning: Type created with compilation errors

SQL> create type item_list is table of item_rec;
2 /

Type created

SQL>

second In a procedure

CREATE OR REPLACE PROCEDURE tst_bom
(t_Result OUT ITEM_LIST)
IS
i NUMBER;
TYPE rec_Item IS RECORD(Item VARCHAR2(20),
desc_ VARCHAR2(30));
TYPE rec_Tab IS TABLE OF REC_ITEM;
Item_Tab REC_TAB;
BEGIN
FOR i IN 1.. 10 LOOP
Item_Tab(i).Item := 'item'
||To_Char(i);

Item_Tab(i).desc_ := 'description'
||To_Char(i);
END LOOP;
END tst_bom;


DECLARE
2 i NUMBER;
3 Item_Tab ITEM_LIST := item_list();
4 t_Result ITEM_LIST;
5 BEGIN
6 FOR i IN 1.. 10 LOOP
7 item_tab.extend;
8 item_tab(i) := item_rec('item'||To_Char(i),'description'||To_Char(i));
9 END LOOP;
10
11 select item_rec(item,desc_) bulk collect into t_result from table(item_tab);
12 for i in 1..item_tab.count loop
13 dbms_output.put_line(t_result(i).item||' '||t_result(i).desc_);
14 end loop;
15 END;
16 /

No comments: