Improve performance by using the nested table and bulk collect into methods of PL/SQL

Source: Internet
Author: User

In Oracle9i, the bulk collect method is added for PL/SQL. You can integrate the retrieved records into a batch of Oracle memory tables to improve the performance of the select into, fetch into or returning into clause.

Example:

Create or replace type performance_obj as object
(
Netlatency number (10)
); Create or replace type performance_tab is table of performance_obj;

Create or replace package pkg_test
As
Type performance_cur is ref cursor;
Procedure spgetperfchartinfo (p_confname in varchar2, p_ret out performance_cur );
End pkg_test;
/

Create or replace package body pkg_test
Procedure spgetperfchartinfo (p_confname in varchar2, p_ret out performance_cur)
Is
V1 number: = 0;
V2 number: = 0;
V3 number: = 0;
V_tab performance_tab: = performance_tab ();
 
Begin
Select performance_obj (C. netlatency) Bulk collect into v_tab
From wmattendeeinfo A, wbxsite B, wmclientperformancedata_tmp C where lower (A. confname) like '%' | p_confname | '%'
And (A. jointime> sysdate-1/3 and A. leavetime is null) and lower (A. sitename) like '% software %'
And a. siteid = B. siteid and A. confid = C. confid and A. siteid = C. siteid;

Select count (*) into V1 from table (cast (v_tab as performance_tab) where netlatency> 0 and netlatency <= 500;
Select count (*) into V2 from table (cast (v_tab as performance_tab) where netlatency> 500 and netlatency <= 1000;
Select count (*) into V3 from table (cast (v_tab as performance_tab) where netlatency> 1000;
 
Open p_ret for select V1 as good, v2 as medium, V3 as poor from dual;
 
End spgetperfchartinfo;
 
End pkg_test;
/

Test Results
Sqlplus> set timing on;
Sqlplus> variable C refcursor;
Sqlplus> exec pkg_test.spgetperfchartinfo ('Meeting ',: C );
Sqlplus> Print C;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.