Skip to Main Content
  • Questions
  • Performance on using oracle Table of an object type

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Rathish MK.

Asked: February 17, 2017 - 7:51 am UTC

Last updated: February 17, 2017 - 3:03 pm UTC

Version: Oracle Database 11g Release 11.2.0.2.0 - 64bit

Viewed 1000+ times

You Asked

Hi

I am working on a reporting tool that extracts data from Oracle Stored Procedures base and generates reports using Jasper. Please find below a sample of the procedure written.

--Creating Object
CREATE OR REPLACE TYPE my_row_type AS OBJECT
(
acid varchar2(10),
foracid varchar2(20),
schm_type varchar2(5),
clr_bal_amt number,
complex number
);
/
--Creating Type
CREATE OR REPLACE TYPE my_tab_type IS TABLE OF my_row_type;
/
--Creating Package
CREATE OR REPLACE PACKAGE types AS
TYPE cursor_type IS REF CURSOR;
END Types;
/
CREATE OR REPLACE
PROCEDURE GetComplexEmpRS (p_solid IN tbaadm.gam.sol_id%TYPE,
p_recordset OUT types.cursor_type) AS
v_tab my_tab_type := my_tab_type();
BEGIN

-- Populate PL/SQL table.
FOR cur_row IN (SELECT acid,foracid,schm_type,clr_bal_amt FROM tbaadm.gam WHERE rownum<3 and sol_id = p_solid) LOOP
v_tab.extend;
v_tab(v_tab.Last) := my_row_type(cur_row.acid, cur_row.foracid, cur_row.schm_type,cur_row.clr_bal_amt,NULL);
END LOOP;

-- Do complex processing that can't be done from SQL alone.
FOR cur_row IN 1 .. v_tab.count LOOP
v_tab(cur_row).complex := v_tab(cur_row).clr_bal_amt;
END LOOP;

-- Open REF CURSOR for outout.
OPEN p_recordset FOR
SELECT acid,
foracid,
schm_type,
clr_bal_amt,
complex
FROM TABLE(CAST(v_tab As my_tab_type))
ORDER BY acid;
END GetComplexEmpRS;
/

By using the TYPE as object is table would there be any issues regarding to the performance on execution of these procedures. All reports are written in the same manner. Kindly advise.

Regards
Rathish MK

and Chris said...

Are you sure the "complex processing" can't be done in SQL? Like, really, really, 100% definitely can't be done sure?

Because loading the data into a PL/SQL first, processing the results, then running a new query using the outcome is almost certainly going to be slower than doing it all in SQL. Though this depends on what your "complex processing" is.

Also: you've got a rownum <= 3 in your original query. But an order by ACID in your refcursor. This can lead to non-deterministic results. For details on how to do this right, read:

http://www.oracle.com/technetwork/issue-archive/2007/07-jan/o17asktom-093877.html

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Plsql to SQL

Rajeshwaran, Jeyabal, February 17, 2017 - 1:38 pm UTC

Looking at the above code, looks like you could erase all the above "Procedural" code and replace them with a SQL like this.

open p_recordset for 
select *
from (
select acid,
 foracid,
 schm_type,
 clr_bal_amt,
 clr_bal_amt complex
 FROM tbaadm.gam
 where sol_id = p_solid
order by acid
   )
where rownum < 3;

Chris Saxon
February 17, 2017 - 3:03 pm UTC

Indeed, I'm assuming it's a simplified example though...

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library