Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: performance question with function returning object type
well, i don't know if there is a better way to do this, but this is how
i got your code to work without calling the function 4x:
SQL> create or replace type res_util_typ 2 as object (pct_util number(4),
3 morn_avail number(4), 4 aftn_avail number(4), 5 eve_avail number(4))
Type created.
SQL> create or replace type blah as table of res_util_typ; 2 /
Type created.
SQL> CREATE OR REPLACE PACKAGE ALLAN_PKG AS
2 function get_utilization return res_util_typ;
3 function get_u return blah;
4 end;
5 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY ALLAN_PKG AS
2 function get_u return blah is
3 rtu res_util_typ;
4 ret blah;
5 begin
6 rtu := get_utilization;
7 ret := blah();
8 ret.extend;
9 ret(1) := rtu;
10 return ret;
11 end;
12 function get_utilization return res_util_typ is
13 retVal res_util_typ; 14 pct_util number(4) := 0; 15 tot_used pls_integer := 0; 16 tot_avail_m pls_integer := 0; 17 tot_avail_a pls_integer := 0; 18 tot_avail_e pls_integer := 0;
Package body created.
SQL> set autot on SQL> set timing on SQL> select pct_util, morn_avail, aftn_avail, eve_avail fromtable(cast(allan_pkg.get_u as blah));
PCT_UTIL MORN_AVAIL AFTN_AVAIL EVE_AVAIL
---------- ---------- ---------- ----------
9999 9999 9999 9999
Elapsed: 00:00:08.92
Execution Plan
SQL>
(i did this in 8i, so i had to change your CASE statements a little bit.)
basically all i did was to create another type ("blah") that is a table of your type, wrote a wrapper function that created a "blah" with a single res_util_typ in it. then, from sql i called the wrapper function with the table(cast( ...)) bit so that it can be accessed as a table in sql.
shrug. there's probably a better workaround to your problem, but until then ... Received on Thu Dec 16 2004 - 11:23:17 CST