An object is a user defined type in 8i/9i/10g.
There are 2 types:
1 Object types - Analogous to a record or structure in a language such as PL/SQL or C, or a class in an object-oriented language such as C++ or Java. Consists of one or more attributes and a set of methods used to manipulate those attributes.
2 Collections - Analogous to arrays, sets, bags, etc., from other languages such as C/C++, Java, or Smalltalk. Collections contain zero or more elements of a given datatype.
The CAST instructs oracle to treat the return set of rows from the PL/SQL function (Emp_function() ) as a collection type.Code:SQL>desc emp Name Null? Type -------------------------------- -------- ---------------- EMPLID NUMBER NAME VARCHAR2(30) DEPTID NUMBER -- create user defined object type create or replace type EmpRecordType as object ( emplid number, name varchar2(30) , deptid number ) / -- create object table create or replace type EmpTableType as table of EmpRecordType; / -- create a function create or replace function emp_function return EmpTableType as I int := 1; emp_data empTableType := empTabletype(); begin for crec in ( select emplid, name, deptid from emp) loop emp_data.extend; emp_data(I) := EmpRecordType( crec.emplid, crec.name, crec.deptid ) ; I := I+1; end loop; return Emp_data; end; / select emplid, name, deptid from TABLE ( cast( Emp_function() as EmpTableType ) ) / EMPLID NAME DEPTID --------- ------------------ ---------- 1001 TAMIL 10 1002 VEERA 20 1003 RAJIV
Is that are you looking for?




Reply With Quote