--Create Database Type as Object
create or replace type TypeForFunction as object (EmpCd number, EmpName Varchar2(60), DepartCode number, Salary number );
--Create table of the Type
Create or replace type TableForFunction as table of TypeForFunction;
--Create Database Function
Create or replace FUNCTION MyFunction (deptCode number) RETURN TableForFunction is OutTableParam TableForFunction; begin select cast( Multiset(select empno, ename, deptno, sal from scott.emp where deptno = deptcode) as TableForFunction) into outtableparam from dual; return OutTableParam; end;
--To return values from this function
SQL> select * from table(MyFunction(10));
Output would be like
EMPCD EMPNAME DEPARTCODE SALARY
---------------------- ------------------------ ---------------------- ----------------------
7782 CLARK 10 2450
7839 KING 10 5000
7934 MILLER 10 1300
can you show this solution wrapped in a package? I think it will work for me, but I'm getting compile errors on the object type when defining the header. New to pl/sql and I have a query that I need to run in a 3rd party app. I want to be able to do a simple select from the package in the app to display multiple rows. Thanks!
ReplyDeleteHi,
DeleteThis might help http://psoug.org/definition/package.htm
Zeeshan
got it to work. Thanks!
DeleteGood to know that :)
Delete