Performance of a stored procedure

Hi all,
10.2.0.1
I have a procedure that takes quite an amount of time to finish its job.
CREATE OR REPLACE PROCEDURE Cpmstxtquery_arr
AS
  f1   utl_file.file_type;
  col  VARCHAR2(2000) := 'col';
BEGIN
  f1 := utl_file.Fopen('CPMS','paymaster.txt','W');
  FOR v1 IN (SELECT   column_name
             FROM     user_tab_columns
             WHERE    table_name = 'PAYMASTER'
             ORDER BY column_id)
  LOOP
    col := col
           ||','
           ||v1.column_name;
  END LOOP;
  col := Substr(col,5);
  utl_file.Put_line(f1,col);
  FOR v1 IN (SELECT   trea_code,
                      gpf_no
             FROM     emp_mast
             WHERE    pc_status = 'Y'
                      --and (delete_flag<>'Y' or delete_flag is null
                      AND trea_code = '8800'
             /*and emp_code in
(select emp_code from mon_act where upto_date='30-SEP-09' and trea_code='8800')
            ORDER BY 1,
                      2)
  LOOP
    FOR v2 IN (SELECT   emp_code,
                        emp_name,
                        gpf_no,
                        tcode,
                        vdate,
                        d_o_b,
                        ddocode,
                        d_o_j,
                        sex,
                        Max(Decode(rank + shift,1,basic,
                                                0)) basic,
                        Max(Decode(rank + shift,1,da_amt,
                                                0)) da_amt,
                        Max(Decode(rank + shift,1,dp_amt,
                                                0)) dp_amt,
                        Max(Decode(rank + shift,1,v_no,
                                                '0')) bochrno,
                        Max(Decode(rank + shift,2,v_no,
                                                '0')) vnoarrear1,
                        Max(Decode(rank + shift,3,v_no,
                                                '0')) vnoarrear2,
                        Max(Decode(rank + shift,4,v_no,
                                                '0')) vnoarrear3,
                        Max(Decode(rank + shift,5,v_no,
                                                '0')) vnoarrear4,
                        Max(Decode(rank + shift,6,v_no,
                                                '0')) vnoarrear5,
                        Max(Decode(rank + shift,1,pencont,
                                                0)) tier1,
                        Max(Decode(rank + shift,1,pencont,
                                                0)) arrtier1,
                        Max(Decode(rank + shift,2,pencont,
                                                0)) arrear1,
                        Max(Decode(rank + shift,3,pencont,
                                                0)) arrear2,
                        Max(Decode(rank + shift,4,pencont,
                                                0)) arrear3,
                        Max(Decode(rank + shift,5,pencont,
                                                0)) arrear4,
                        Max(Decode(rank + shift,6,pencont,
                                                0)) arrear5,
                        Max(Decode(rank + shift,1,v_date,
                                                To_date('01/01/1900','DD/MM/YYYY'))) recv_date,
                        Max(Decode(rank + shift,2,v_date,
                                                To_date('01/01/1900','DD/MM/YYYY'))) vouchdt1,
                        Max(Decode(rank + shift,3,v_date,
                                                To_date('01/01/1900','DD/MM/YYYY'))) vouchdt2,
                        Max(Decode(rank + shift,4,v_date,
                                                To_date('01/01/1900','DD/MM/YYYY'))) vouchdt3,
                        Max(Decode(rank + shift,5,v_date,
                                                To_date('01/01/1900','DD/MM/YYYY'))) vouchdt4
               FROM     (SELECT   emp_code,
                                  emp_name,
                                  tcode,
                                  v_no,
                                  gpf_no,
                                  ddocode,
                                  basic,
                                  pencont,
                                  sex,
                                  da_amt,
                                  dp_amt,
                                  vdate,
                                  d_o_b,
                                  d_o_j,
                                  v_date,
                                  upto_date,
                                  Row_number()
                                    OVER(PARTITION BY v_date ORDER BY upto_date DESC) rank,
                                  (CASE
                                     WHEN EXISTS (SELECT NULL
                                                  FROM   mon_act
                                                  --where trunc(v_date,'mmyyyy')=trunc(upto_date,'mmyyyy')
                                                 --and trunc(v_date,'mmyyyy')=trunc(c.v_date,'mmyyyy'))
                                                 WHERE To_char(v_date,'YYYYMM') = To_char(c.upto_date,'YYYYMM')
                                                         AND To_char(v_date,'YYYYMM') = To_char(c.v_date,'YYYYMM'))
                                     THEN 0
                                     ELSE 1
                                   END) shift
                         FROM     (SELECT a.emp_code                  emp_code,
                                          emp_name,
                                          a.v_no                      v_no,
                                          b.gpf_no                    gpf_no,
                                          b.sex                       sex,
                                          b.d_o_b                     d_o_b,
                                          b.d_o_j                     d_o_j,
                                          a.v_date                    v_date,
                                          a.basic                     basic,
                                          (a.pen_cont + a.pen_cont)   pencont,
                                          a.ddo_code                  ddocode,
                                          da_amt,
                                          dp_amt,
                                          a.trea_code                 tcode,
                                          To_char(a.v_date,'YYYYMON') vdate,
                                          a.upto_date                 upto_date
                                   FROM   mon_act a,
                                          emp_mast b
                                   WHERE  a.emp_code = b.emp_code
                                          AND a.trea_code = b.trea_code
                                          AND a.pen_cont > 0
                                          --and gpf_no like '%11203%'
                                          AND gpf_no = v1.gpf_no
                                          AND v_no != '.'
                                          AND To_char(v_date,'MONYY') = 'SEP09'
                                          AND a.trea_code = '8800') c
                         ORDER BY gpf_no)
               GROUP BY emp_code,
                        emp_name,
                        gpf_no,
                        tcode,
                        vdate,
                        d_o_b,
                        d_o_j,
                        sex,
                        ddocode)
    LOOP
      utl_file.Put_line(f1,0
                           ||','
                           ||Regexp_replace(v2.gpf_no,'[A-Z._%-%/%\%;%:%-%=%.%,%-]')
                           ||','
                           ||v2.tcode
                           ||','
                           ||v2.bochrno
                           ||','
                           ||'NULL'
                           ||','
                           ||v2.recv_date
                           ||','
                           ||v2.basic
                           ||','
                           ||v2.dp_amt
                           ||','
                           ||v2.da_amt
                           ||','
                           ||To_char(To_date(v2.vdate,'YYYYMON'),'YYYY')
                           ||','
                           ||To_char(To_date(v2.vdate,'YYYYMON'),'MON')
                           ||','
                           ||((v2.tier1) / 2)
                           ||','
                           ||((v2.tier1) / 2)
                           ||','
                           ||0
                           ||','
                           ||0
                           ||','
                           ||v2.tier1
                           ||','
                           ||v2.arrear1
                           ||','
                           ||v2.arrear2
                           ||','
                           ||(((v2.arrear1 / 2)) + ((v2.arrear1 / 2)) + 0 + 0)
                           ||','
                           ||0
                           ||','
                           ||SYSDATE
                           ||','
                           ||'NULL'
                           ||','
                           ||v2.vnoarrear1
                           ||','
                           ||'NULL'
                           ||','
                           ||'NULL'
                           ||','
                           ||v2.arrear3
                           ||','
                           ||v2.arrear4
                           ||','
                           ||v2.arrear5
                           ||','
                           ||'NULL'
                           ||','
                           ||'0'
                           ||','
                           ||v2.vnoarrear2
                           ||','
                           ||v2.vnoarrear3
                           ||','
                           ||v2.vnoarrear4
                           ||','
                           ||v2.vnoarrear5
                           ||','
                           ||v2.vouchdt1
                           ||','
                           ||v2.vouchdt2
                           ||','
                           ||v2.vouchdt3
                           ||','
                           ||v2.vouchdt4
                           ||','
                           ||v2.ddocode
                           ||','
                           ||v2.emp_code
                           ||','
                           ||v2.gpf_no
                           ||','
                           ||v2.emp_name);
    END LOOP;
  END LOOP;
  utl_file.Fclose(f1);
END; Below is the tkprof sample.
TKPROF: Release 10.2.0.1.0 - Production on Thu Feb 4 16:25:14 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Trace file: treasury_ora_24016.trc
Sort options: default
count    = number of times OCI procedure was executed
cpu      = cpu time in seconds executing
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
BEGIN cpmstxtquery_arr; END;
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.59          0          0          0           0
Execute      1      0.31       3.53          0          0          0           1
Fetch        0      0.00       0.00          0          0          0           0
total        2      0.31       4.12          0          0          0           1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 63  (IPAO)
Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                       1        0.00          0.00
  SQL*Net message from client                     1        0.00          0.00
SELECT COLUMN_NAME
FROM
USER_TAB_COLUMNS WHERE TABLE_NAME='PAYMASTER' ORDER BY COLUMN_ID
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.02       0.03          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.00       0.00          0          3          0           0
total        3      0.02       0.03          0          3          0           0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 63  (IPAO)   (recursive depth: 1)
error during execute of EXPLAIN PLAN statement
ORA-01039: insufficient privileges on underlying objects of the view
parse error offset: 92
SELECT TREA_CODE,GPF_NO
FROM
EMP_MAST WHERE PC_STATUS='Y' AND TREA_CODE='8800' ORDER BY 1,2
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch       11      0.01       2.52        169       2532          0        1048
total       13      0.01       2.52        169       2532          0        1048
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 63  (IPAO)   (recursive depth: 1)
Rows     Execution Plan
      0  SELECT STATEMENT   MODE: ALL_ROWS
      0   SORT (ORDER BY)
      0    TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF 'EMP_MAST'
               (TABLE)
      0     INDEX   MODE: ANALYZED (RANGE SCAN) OF 'EMPCODE_EM' (INDEX)
Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  db file sequential read                       169        1.10          2.50
SELECT EMP_CODE,EMP_NAME,GPF_NO,TCODE,VDATE, D_O_B,DDOCODE,D_O_J,SEX,
  MAX(DECODE(RANK+SHIFT,1,BASIC,0))BASIC, MAX(DECODE(RANK+SHIFT,1,DA_AMT,0))
  DA_AMT, MAX(DECODE(RANK+SHIFT,1,DP_AMT,0))DP_AMT, MAX(DECODE(RANK+SHIFT,1,
  V_NO,'0'))BOCHRNO, MAX(DECODE(RANK+SHIFT,2,V_NO,'0'))VNOARREAR1,
  MAX(DECODE(RANK+SHIFT,3,V_NO,'0'))VNOARREAR2, MAX(DECODE(RANK+SHIFT,4,V_NO,
  '0'))VNOARREAR3, MAX(DECODE(RANK+SHIFT,5,V_NO,'0'))VNOARREAR4,
  MAX(DECODE(RANK+SHIFT,6,V_NO,'0'))VNOARREAR5, MAX(DECODE(RANK+SHIFT,1,
  PENCONT,0))TIER1, MAX(DECODE(RANK+SHIFT,1,PENCONT,0))ARRTIER1,
  MAX(DECODE(RANK+SHIFT,2,PENCONT,0))ARREAR1, MAX(DECODE(RANK+SHIFT,3,PENCONT,
  0))ARREAR2, MAX(DECODE(RANK+SHIFT,4,PENCONT,0))ARREAR3,
  MAX(DECODE(RANK+SHIFT,5,PENCONT,0))ARREAR4, MAX(DECODE(RANK+SHIFT,6,PENCONT,
  0))ARREAR5, MAX(DECODE(RANK+SHIFT,1,V_DATE,TO_DATE('01/01/1900',
  'DD/MM/YYYY')))RECV_DATE, MAX(DECODE(RANK+SHIFT,2,V_DATE,
  TO_DATE('01/01/1900','DD/MM/YYYY')))VOUCHDT1, MAX(DECODE(RANK+SHIFT,3,
  V_DATE,TO_DATE('01/01/1900','DD/MM/YYYY')))VOUCHDT2, MAX(DECODE(RANK+SHIFT,
  4,V_DATE,TO_DATE('01/01/1900','DD/MM/YYYY')))VOUCHDT3,
  MAX(DECODE(RANK+SHIFT,5,V_DATE,TO_DATE('01/01/1900','DD/MM/YYYY')))VOUCHDT4
FROM
(SELECT EMP_CODE,EMP_NAME ,TCODE, V_NO, GPF_NO,DDOCODE, BASIC,PENCONT, SEX,
  DA_AMT,DP_AMT, VDATE, D_O_B, D_O_J, V_DATE, UPTO_DATE, ROW_NUMBER()
  OVER(PARTITION BY V_DATE ORDER BY UPTO_DATE DESC) RANK, (CASE WHEN
  EXISTS(SELECT NULL FROM MON_ACT WHERE TO_CHAR(V_DATE,'YYYYMM')=
  TO_CHAR(C.UPTO_DATE,'YYYYMM') AND TO_CHAR(V_DATE,'YYYYMM')=TO_CHAR(C.V_DATE,
  'YYYYMM')) THEN 0 ELSE 1 END)SHIFT FROM (SELECT A.EMP_CODE EMP_CODE,
  EMP_NAME,A.V_NO V_NO, B.GPF_NO GPF_NO,B.SEX SEX, B.D_O_B D_O_B,B.D_O_J
  D_O_J,A.V_DATE V_DATE, A.BASIC BASIC,(A.PEN_CONT+A.PEN_CONT)PENCONT,
  A.DDO_CODE DDOCODE,DA_AMT,DP_AMT, A.TREA_CODE TCODE,TO_CHAR(A.V_DATE,
  'YYYYMON')VDATE,A.UPTO_DATE UPTO_DATE FROM MON_ACT A,EMP_MAST B WHERE
  A.EMP_CODE=B.EMP_CODE AND A.TREA_CODE=B.TREA_CODE AND A.PEN_CONT>0 AND
  GPF_NO=:B1 AND V_NO!='.' AND TO_CHAR(V_DATE,'MONYY')='SEP09' AND
  A.TREA_CODE='8800')C ORDER BY GPF_NO) GROUP BY EMP_CODE,EMP_NAME,GPF_NO,
  TCODE,VDATE,D_O_B,D_O_J, SEX,DDOCODE
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.00          0          0          0           0
Execute   1048      0.10       0.16          0          0          0           0
Fetch     1048    867.19     896.74     571482   35373707          0         707
total     2097    867.30     896.92     571482   35373707          0         707
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 63  (IPAO)   (recursive depth: 1)
Rows     Execution Plan
      0  SELECT STATEMENT   MODE: ALL_ROWS
      0   HASH (GROUP BY)
      0    VIEW
      0     WINDOW (SORT)
      0      TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                 'MON_ACT' (TABLE)
      0       NESTED LOOPS
      0        TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                   'EMP_MAST' (TABLE)
      0         INDEX   MODE: ANALYZED (RANGE SCAN) OF 'EMPCODE_EM'
                    (INDEX)
      0        INDEX   MODE: ANALYZED (RANGE SCAN) OF 'PK_MONACT'
                   (INDEX (UNIQUE))
Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  db file sequential read                      5106        0.62         13.91
  db file scattered read                      41012        0.91         38.84
  latch: cache buffers chains                    28        0.02          0.21
  latch: shared pool                              1        0.22          0.22
  latch: library cache                            1        0.00          0.00
  latch free                                      4        0.00          0.00
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.59          0          0          0           0
Execute      1      0.31       3.53          0          0          0           1
Fetch        0      0.00       0.00          0          0          0           0
total        2      0.31       4.12          0          0          0           1
Misses in library cache during parse: 1
Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                       2        0.00          0.00
  SQL*Net message from client                     1        0.00          0.00
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call     count       cpu    elapsed       disk      query    current        rows
Parse       67      0.05       0.09          0          0          0           0
Execute   1160      0.14       0.49          0          0          0           0
Fetch     1412    867.22     905.88     571675   35376783          0        2099
total     2639    867.42     906.47     571675   35376783          0        2099
Misses in library cache during parse: 31
Misses in library cache during execute: 29
Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  db file sequential read                      5299        1.43         22.77
  db file scattered read                      41012        0.91         38.84
  latch: cache buffers chains                    28        0.02          0.21
  latch: shared pool                              1        0.22          0.22
  latch: library cache                            1        0.00          0.00
  latch free                                      4        0.00          0.00
    4  user  SQL statements in session.
  110  internal SQL statements in session.
  114  SQL statements in session.
    2  statements EXPLAINed in this session.
Trace file: treasury_ora_24016.trc
Trace file compatibility: 10.01.00
Sort options: default
       1  session in tracefile.
       4  user  SQL statements in trace file.
     110  internal SQL statements in trace file.
     114  SQL statements in trace file.
      32  unique SQL statements in trace file.
       2  SQL statements EXPLAINed using schema:
           IPAO.prof$plan_table
             Default table was used.
             Table was created.
             Table was dropped.
   49894  lines in trace file.
     910  elapsed seconds in trace file.Is there any chance of improving the performance?
Thanks
Edited by: Hashmi on Feb 4, 2010 3:46 AM
Edited by: Hashmi on Feb 4, 2010 3:50 AM

Hashmi,
Following on what others have suggested, is following a way to combine two queries ?
I have only used innermost part of your second query but you should be able to build rest if this is correct.
SELECT a.emp_code                  emp_code,
                                          emp_name,
                                          a.v_no                      v_no,
                                          b.gpf_no                    gpf_no,
                                          b.***                       ***,
                                          b.d_o_b                     d_o_b,
                                          b.d_o_j                     d_o_j,
                                          a.v_date                    v_date,
                                          a.basic                     basic,
                                          (a.pen_cont + a.pen_cont)   pencont,
                                          a.ddo_code                  ddocode,
                                          da_amt,
                                          dp_amt,
                                          a.trea_code                 tcode,
                                          To_char(a.v_date,'YYYYMON') vdate,
                                          a.upto_date                 upto_date
                                   FROM   mon_act a,
                                          emp_mast b
                                   WHERE  a.emp_code = b.emp_code
                                          AND a.trea_code = b.trea_code
                                          AND a.pen_cont > 0
                                          --and gpf_no like '%11203%'
                                          *AND pc_status = 'Y'*
                                          *AND trea_code = '8800'*
                                          AND v_no != '.'
                                          AND To_char(v_date,'MONYY') = 'SEP09'
                                          AND a.trea_code = '8800'Also, your TkProf shows that your second query is executed 1048 times (once for each row of outer query) but produces only 707 rows. Unless I am missing something obvious (its Friday :) ), it means there are some values of GPF_NO, generated by outer query, which cause inner query to generate zero rows. The additional executions probably also contribute to the enormous amount of consistent gets. Another reason to combine 2 queries ??

Similar Messages

  • Best approach for performing DMLs using stored procedures

    Hi,
    I have a really general question and would like to hear your say about this.
    I want my application to manipulate or read data using stored procedures (or packages in that manner) and not directly using queries against the DB.
    Let's say I have a table with many columns:
    create table test (pkid number(10),col1 varchar2(30), col2 number(10), col3 date,...);For such a DML procedure, is it best to do something like
    procedure do_update(i_pkid IN number,i_col1 IN varchar2, i_col2 IN number, i_col3 IN date,...) as
    begin
       update test
       set col1=i_col1,
            col2=i_col2,
            col3=i_col3...
       where pkid=i_pkid;
       commit;
    end;Or do a selective update, meaning update only a certain column every time, given only 1 column actually changes? (and how to do that - separate procedures for each column? [columns can be nulls])
    Also, is it better to work with test.col1%type instead of specifying the data type in the procedure?
    And one last question - If I have a table with 100 columns and I don't want to create a procedure with 100 parameters - the best approach would be to use a record?
    I just need to be set on the way I start implementing things in order to do it well from the start.
    Many thanks.
    Edited by: Pyrocks on Nov 17, 2010 1:58 PM

    Pyrocks wrote:
    One last clarification (although it may be more related to c/c++ developers - maybe one of you will know):
    We are working with C++ and VB against a SQLServer and my part is to translate all the existing procedures to Oracle in order to migrate the application to work with Oracle DB.
    The existing procedures use an IN parameter for each column in the table and I would really like to use rowtype like you mentioned.
    Since I'm not a c/c++/vb developer - is there an easy way of working with such types, or even User-Defined Types, from c/c++/vb (as in passing a rowtype record from c++ to a SP ?)
    I'm not looking for the actual way - just want to know how hard it would be and how much code needs to be changed in order to be able to convince the developers that this is the RIGHT way to work.
    PS. none of our developers have experience with ORACLE so they wouldn't know the answer...Not actually an Oracle server-side (SQL language or PL/SQL language) question - but a client one. And it has been a long time since I wrote a fat client using C/C++ or Delphi.
    The OCI (<i>Oracle Call Interface</i>) supports advance (user defined) SQL data types. Has since Oracle 8i. So in that respect, yes the client can support custom SQL data types.
    How well it does depends entirely on that client language's features wrt OCI integration. For example, Delphi 4 was release around Oracle 8i and supported custom SQL types. I would expect that most languages today (like Java and C#) will provide support for it.
    As for usiong +%ROWTYPE+ - this is a PL/SQL clause as far as I know. Unsure whether it is supported by the OCI. What could support it is a pre-compiler like Pro*C. These enable you to mix pseudo SQL source code with client language source code. The pre-compilation step then replaces the pseudo SQL code with native client language calls to the OCI. The code is then compiled by that client language's compiler. Pre-compilers can pull all kinds of interesting "tricks" with their pseudo SQL code support.
    The best would be to consult the applicable client language's manuals that describe the interface it supports (via OCI) to Oracle.

  • Insert performance inside a stored procedure

    Hi,
    I have an insert statement that inserts approx 400,000 records. The insert executes in 7 seconds if I run it from my SQL command. But when the same insert is executed as part of stored procedure, it takes ~30 mins. This is not the case with all large inserts. The behavior is sporadic - it happens with different insert statement at different times.
    Please advise how I can tune this.
    Thanks,
    Phani

    Hello,
    Post your procedure code here along with insert statement.
    Regards

  • Performance of Stored procedures against Prepared Statements

    What will be the exact difference in the performance between implementing stored procedures and prepared statements ?

    Short answer: it depends.
    There will probobaly be very little difference in performance difference for a sipmle insert / update etc.
    Multiple inserts / updates etc you will probobaly find faster with a stored procedure rather than n prepared statments as you only have to contact the database once vs n times.
    Hope this helps!

  • Bulk Insert Through Stored Procedure performance issue

    Hello,
    i am new to oracle. i am writing a stored procedure through which i want to insert 1 billion record in a table. but it takes days to insert it . please tell me how can i improve performance of my stored procedure. because same stored procedure when i convert it into sql server in take 24 - 30 min to insert 1 billion record.
    Code of my stored procedure are as follows :
    create or replace PROCEDURE bspGenerateHSCode(
    mLoc_id IN INT,
    HSCodeStart IN VARCHAR2,
    HSCodeEnd IN VARCHAR2,
    mRqstId IN INT,
    total_count IN INT,
    Status OUT INT)
    AS
    ExitFlag INT;
    row_count INT;
    mBatchStart NUMBER;
    mBatchEnd NUMBER;
    mStartSqnc NUMBER;
    mEndSqnc NUMBER;
    mHSCode VARCHAR2(500);
    HSStartStr VARCHAR2(500);
    BEGIN
    SELECT COUNT(*) INTO row_count FROM goap_eal_allocation
                   WHERE hs_code_start = HSCodeStart
    AND hs_code_end = HSCodeEnd
    AND loc_id = mLoc_id
    AND processed = 0;
    IF row_count > 0 THEN
    SELECT CAST ( REVERSE(substr(REVERSE(HSCodeStart), 1, instr(REVERSE(HSCodeStart), ',') -1)) AS NUMBER) INTO mStartSqnc FROM DUAL;
    SELECT CAST ( REVERSE(substr(REVERSE(HSCodeEnd), 1, instr(REVERSE(HSCodeEnd), ',') -1)) AS NUMBER) INTO mEndSqnc FROM DUAL;
    SELECT CAST( REVERSE(substr( REVERSE(HSCodeStart), instr(REVERSE(HSCodeStart), ','))) AS VARCHAR2(500) ) INTO HSStartStr FROM DUAL;
    mBatchStart := mStartSqnc;
    DBMS_OUTPUT.PUT_LINE('start batch ' || mBatchStart);
    LOOP
    mBatchEnd := mBatchStart + 5000;
    IF mBatchEnd > mEndSqnc THEN
    mBatchEnd := mEndSqnc + 1;
    END IF;
    DBMS_OUTPUT.PUT_LINE('End batch ' || mBatchEnd);
    LOOP
    mHSCode := HSStartStr || mBatchStart;
    mBatchStart := mBatchStart + 1;
    INSERT INTO goap_eal_register(id, hs_code, loc_id, status_id, synced)
    SELECT CASE WHEN MAX(id) > 0 THEN (MAX(id) + 1) ELSE 1 END AS id ,
    mHSCode, mLoc_id, 6, 1 FROM goap_eal_register;
    EXIT WHEN mBatchStart = mBatchEnd;
    END LOOP;
    COMMIT;
    EXIT WHEN mBatchStart = mEndSqnc +1;
    END LOOP;
    UPDATE goap_eal_allocation SET processed = 1
    WHERE hs_code_start = HSCodeStart
    AND hs_code_end = HSCodeEnd
    AND loc_id = mLoc_id;
    COMMIT;
    Status := 1;
    ELSE
    Status := 0;
    END IF;
    END;
    Thanks

    Please edit your post and add \ on the line before and the line after the code to preserve formattingsee how this looks?
    Also, when you basically just want to RETURN without doing any work then your first test should just RETURN if you don't want to do any work.
    Instead of what your code does:IF row_count > 0 THEN
    . . . a whole lot of code that is hard to read or understand
    COMMIT;
    Status := 1;
    ELSE
    Status := 0;
    END IF;
    Test the condition to determine when you do NOT want proceed and just return.IF row_count = 0 THEN
    Status := 0;
    RETURN;
    END IF;
    -- now NONE of the following code needs to be indented - you won't get here unless you really want to execute it.
    . . . break the code into separate steps and add a one line comment before each step that says what that step does.
    COMMIT;
    Status := 1;

  • What happens to the report if the underlying stored procedure to execute the report take atleast 3 hrs to run

    Hi,
    I have a report which is calling a stored procedure..
    Stored procedure exceutes 4-5 stored procedure and then returns the count each procedure it ran using union all statement... The stored procedure takes around 3-4 hrs to run because it is looking at quarterly data and YTD data.
    So once the report is kicked off and the procedure behind it runs and runs how will communicate to the report to show the final data... the final data will just be 5 rows with counts.
    I think we are running into a issue where the stored procedure runs and runs and then the report goes into la la land and has no clue what to do...
    Can you please shed some light on this..
    Thanks
    Karen

    Hi Karen,
    When we render a report, the report would process the following procedures:
    Open connections to data source and reading data rows from data extensions for all datasets, means retrieve data. Then process the engine requests, including the tablix, grouping, sorting, filtering, aggregations and subreport processing, means process report.
    Finally, render the report, including the pagination modules and on-demand expression evaluations.
    So the report rending has to wait until the stored procedure is executed. To improve the performance, we can consider the three aspects:
    Improve the performance of the stored procedures. Such as index and join. For better support, I suggest you can post a new thread about this issue in Transact-SQL forum at:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=transactsql. It is appropriate and more experts will assist you.
    Simplify the report. For example, avoid including a reference to [&TotalPages] or any complex expressions in the page header and page footer. For more details, please see the following document:
    http://technet.microsoft.com/en-us/library/bb522806(v=sql.105).aspx
    Using cashing if you have a long-running query that cannot be tuned further. For more details, please refer to the following article:
    http://msdn.microsoft.com/en-us/library/ms159241(v=sql.110).aspx
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Flags needs to set to run stored procedure fast

    Hi,
    I need to understand what all flags that we need to set run stored procedure fast.
    e.g. set no count on command is one option, please redirect me to other command so that I can use those for each stored procedure.

    That is the only general option, however, no relationship to performance.  Other options may be appropriate depending on the program statements.
    To achieve good performance, optimize the stored procedure:
    http://www.sqlusa.com/articles/query-optimization/
    The underlying principles of stored procedure optimization:
    1. Each statement must be optimized
    2. Avoid unnecessary statements & excessive looping
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Editing Stored Procedures (SQL Server?)

    This may seem like a dumb question but I just finished my project for our Oracle data warehouse and now I need to move on to SQL Server to upgrade those procedures... does SQL Developer not support the editing of SPs for SQL Server? Are the SPs for SQL Server read-only?
    Using SQL Developer Version 1.5.0.53.58
    on Win XP box...
    Thanks!
    Tim

    Hello,
    Please try the following ones:
    http://msdn.microsoft.com/en-us/library/ms190669.aspx
    http://www.sql-server-performance.com/2003/stored-procedures-basics/
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Improve the performance in stored procedure using sql server 2008 - esp where clause in very big table - Urgent

    Hi,
    I am looking for inputs in tuning stored procedure using sql server 2008. l am new to performance tuning in sql,plsql and oracle. currently facing issue in stored procedure - need to increase the performance by code optmization/filtering the records using where clause in larger table., the requirement is Stored procedure generate Audit Report which is accessed by approx. 10 Admin Users typically 2-3 times a day by each Admin users.
    It has got CTE ( common table expression ) which is referred 2  time within SP. This CTE is very big and fetches records from several tables without where clause. This causes several records to be fetched from DB and then needed processing. This stored procedure is running in pre prod server which has 6gb of memory and built on virtual server and the same proc ran good in prod server which has 64gb of ram with physical server (40sec). and the execution time in pre prod is 1min 9seconds which needs to be reduced upto 10secs or so will be the solution. and also the exec time differs from time to time. sometimes it is 50sec and sometimes 1min 9seconds..
    Pl provide what is the best option/practise to use where clause to filter the records and tool to be used to tune the procedure like execution plan, sql profiler?? I am using toad for sqlserver 5.7. Here I see execution plan tab available while running the SP. but when i run it throws an error. Pl help and provide inputs.
    Thanks,
    Viji

    You've asked a SQL Server question in an Oracle forum.  I'm expecting that this will get locked momentarily when a moderator drops by.
    Microsoft has its own forums for SQL Server, you'll have more luck over there.  When you do go there, however, you'll almost certainly get more help if you can pare down the problem (or at least better explain what your code is doing).  Very few people want to read hundreds of lines of code, guess what's it's supposed to do, guess what is slow, and then guess at how to improve things.  Posting query plans, the results of profiling, cutting out any code that is unnecessary to the performance problem, etc. will get you much better answers.
    Justin

  • Performance problem with java stored procedure

    hi,
    i developped a java class, then I stored it in Oracle 8.1.7.
    This class contains several import of other classes stored in the database.
    It works, but the execution perfomances are disappointing. It's very long. I guess, that's because of the great number of classes to load that are necessary for my class execution.
    I tried to increase the size of the java pool (I parameter 70 Mo in the java_pool_size parameter of the init.ora), but the performance is not much better.
    Has anyone an idea to increase the performance of this execution of my class ?
    In particular, is there a way to keep permanently in memory the java objects used by my class ?
    Thanks in advance
    bye
    [email protected]
    null

    before running Java, the database session needs to be Java enabled; this might be the reason why it is taking so long. If this is the case, you should see an improvement in subsequent calls, once a database session is Java enabled, other users can benefit from it.
    Kuassi
    I have some performance issue with java stored procedure. Hope some one will be able to help me out. I'm using java stored procedures in my application and basically these procedures are used to do some validation and form the XML message of the database tables. I have noticed that when I call the PL/SQL wrapper function, it is taking time to load the java class and once the class is loaded the execution is faster. Most of the time is spent for loading the class rather than executing the function. if I reduce the class load time, I can improve the performance drastically. Do any one of you know how to reduce the class load time. The following are the platform and oracle version.
    O/S: IBM AIX
    Oracle: 8.1.7

  • How to check performance for Stored procedure or Package.

    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.

    user13483989 wrote:
    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.Oracle has provided set of Tools to monitor the Performance.
    Profilers being one of them; If you wish to understand more on PL/SQL Optimization, please read PL/SQL Optimization and Tuning.
    See example of DBMS_PROFILER.
    See example of PLSQL Hierarchial Profiler

  • ** JDBC Receiver - Oracle Stored Procedure - Large Records - Performance

    Hi friends,
    In my File to JDBC scenario, I use Oracle SP. I designed my target structure as mentioned in help.sap.com. In this scenario, the Sender file sends large no. of records, we have to update those records in the Oracle table. As per this requirement, I did mapping. I tested one file with 4 records. In SXMB_MONI, mapping works fine. I have given below the target payload. The message is processed successfully. (Still I have not created SP in database I am unable to check for the updating of records in the table).
    My doubt is
    1) Whether the target payload is correct ?
    2) For each <STATMENT> tag, Will XI establish connectivity to JDBC and update the record ? If it is, in real time if we send large no. of records, ex: 50 thousand records, performance isssu will come or not?
    3) How to solve the problem as said in point 2. (LookUp procedure etc)
    Kindly reply friends. (If you  have faced this problem ... kindly reply how to solve this issue)
    Target Payload:
    <?xml version="1.0" encoding="utf-8"?>
    <ns1:PSABCL_Mumbai xmlns:eds="http://sdn.sap.com/sapxsl" xmlns:ns0="http://abc.xyz.com" xmlns:ns1="http://abc.xyz.com/ABCL/Finance">
    <STATEMENT>
    <SP_ABCL ACTION="EXECUTE">
    <IF_ROW_STAT>FOR_IMPORT</IF_ROW_STAT><CON_FST_NAME>John</CON_FST_NAME><CON_LAST_NAME>Test001915</CON_LAST_NAME><CON_MID_NAME>W</CON_MID_NAME>
    </SP_ABCL>
    </STATEMENT>
    <STATEMENT>
    <SP_ABCL ACTION="EXECUTE">
    <IF_ROW_STAT>FOR_IMPORT</IF_ROW_STAT><CON_FST_NAME>Josephine</CON_FST_NAME><CON_LAST_NAME>Walker</CON_LAST_NAME><CON_MID_NAME>Rose</CON_MID_NAME>
    </SP_ABCL>
    </STATEMENT>
    <STATEMENT>
    <SP_ABCL ACTION="EXECUTE">
    </SP_ABCL>
    </STATEMENT>
    <STATEMENT>
    <SP_ABCL ACTION="EXECUTE">
    </SP_ABCL>
    </STATEMENT>
    </ns1:PSABCL_Mumbai>
    Thanking You.
    Kind Regards,
    Jegathees P.

    Hi,
    The structure should be -
    <MsgType Name>
    <StatementName>
    <storedProcedureName action = "EXECUTE">
    <table>
    <List of Parameters isInput = "true" type = "STRING">
    Map the table node to the stored procedure name.
    Also,
    For each statement, XI would make a database call. For better performance, do not check the button in CC - Open a new connection to database for each message.
    Also another solution would be, collect all the data in the mapping to a comma or a pipe separated string in the mapping and have the statement node created only once. This way, though you have 5000 records, they all will be given to the SP in one DB call. you can also manage the mapping so that you will not send more the the X number of records to database in a single call. We are using an XML created in code in an UDF for this. The SP has to take care of stripping the comma or pipe separated values or the XML sent as a string input parameter.
    VJ

  • Stored procedure Performance issue in SQLserver 2005

    Hi All,
    i am inserting the data to Database by using of Stored procedure in target DB.
    My source structure and target structures are looking below
    I have the source structure having lot of rows and look like my structure is below:
    <?xml version="1.0" encoding="utf-8" ?>
    <ns0:POCA0013_KANLOG_REQUEST_MT_response xmlns:ns0="urn:com:POCA0013:sample">
    <SCMDB_response>
    -  <row>
          <PROJK>O-USA</PROJK>
          <KOLLO>123</KOLLO>
       </row>
    -  <row>
          <PROJK>O-Denmark</PROJK>
          <KOLLO>256</KOLLO>
       </row>
        n  number of rows
    </SCMDB_KANLOGVIEW_response>
    </ns0:POCA0013_KANLOG_REQUEST_MT_response>
    and after mapping my target structure is coming to like this.
    <?xml version="1.0" encoding="UTF-8" ?>
    <ns0:POCA0013_DB_MT xmlns:ns0="urn:pg-com POCA0013:sample">
    <StatmentName>
       <XI_SP_DATA action="EXECUTE">
         <PROJEK isInput="TRUE" type="CHAR">O-USA</PROJEK>
         <KOLLO isInput="TRUE" type="CHAR" >123</KOLLO>
       </XI_SP_DATA>
    </StatmentName>
    <StatmentName>
       <XI_SP_DATA action="EXECUTE">
         <PROJEK isInput="TRUE" type="CHAR">O-Denmark</PROJEK>
         <KOLLO isInput="TRUE" type="CHAR" />256</KOLLO>
       </XI_SP_DATA>
    </StatmentName>
      N number of times
    </ns0:POCA0013_DB_MT>
    this is working perfectly to insert the records into the database by using stored procedure. each record  it call the stored procedure for insert the records, for example we had 100 records and it call 100 times stored procedure.
    But in case of huge data, for example 10000 records, it call the 10000 times to stored procedure.in that case we had a problem for database side.
    we have  one reason to use the stored procedure here, because once insert the data into table, if successful log table is created with successful status , if not log table is created with error status. for that purpose i am using stored procedure here.
    Our customer wants to call the stored procedure for one time for all records.How i can manage this situation.
    Can you give me your valuble ideas about this problem.
    Thank you very much.,
    Sateesh
    Edited by: sateesh kumar .N on Apr 23, 2010 6:53 AM
    Edited by: sateesh kumar .N on Apr 23, 2010 6:54 AM
    Edited by: sateesh kumar .N on Apr 23, 2010 7:54 AM

    Hi Sateesh,
    how about a different approach.
    Add 2 more tables to your solution. The first table is used as a staging table, where PI inserts all the data without making any checks, whatsoever. The second table is used as a control table. If the insertion is finished, a log entry is inserted into this second table, containing the information about success or failure or how many rows had been inserted. Put an insert trigger on this table, which in term starts a stored procedure. This stored procedure can read all the data from the staging table and put it into the desired target tables. Additionally you can perform plausiblitiy checks inside this SP.
    Okay I know, this is a complete new solution in comparison to what you did before. But in my experience, this will be much more performant than 10000 calls to one stored procedure who only does inserts as you described.
    Regards
    Sven

  • Performance to fetch result set from stored procedure.

    I read some of related threads, but couldn't find any good suggestions about the performance issue to fetch the result set from a stored procedure.
    Here is my case:
    I have a stored procedure which will return 2,030,000 rows. When I run the select part only in the dbartisan, it takes about 3 minutes, so I know it's not query problem. But when I call the stored procedure in DBArtisan in following way:
    declare cr SYS_REFCURSOR;
    firstname char(20);
    lastname char(20);
    street char(40);
    city char(20);
    STATE varchar2(2);
    begin DISPLAY_ADDRESS(cr);
    DBMS_OUTPUT.ENABLE(null);
    LOOP
    FETCH cr INTO firstname,lastname,street, city, state;
    EXIT WHEN cr%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE( firstname||','|| lastname||','|| street||',' ||city||',' ||STATE);
    END LOOP;
    CLOSE cr;
    end;
    It will take about 100 minutes. When I used DBI fetchrow_array in perl code, it took about same amount of time. However, same stored procedure in sybase without using cursor, and same perl code, it only takes 12 minutes to display all results. We assume oracle has better performance. So what could be the problem here?
    The perl code:
    my $dbh = DBI->connect($databaseserver, $dbuser, $dbpassword,
    { 'AutoCommit' => 0,'RaiseError' => 1, 'PrintError' => 0 })
    or die "couldn't connect to database: " . DBI->errstr;
    open OUTPUTFILE, ">$temp_output_path";
    my $rc;
    my $sql="BEGIN DISPLAY_ADDRESS(:rc); END;";
    my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->bind_param_inout(':rc', \$rc, 0, { ora_type=> ORA_RSET });
    $sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
    while($address_info=$rc->fetchrow_arrayref()){
    my ($firstname, $lastname, $street, $city, $STATE) = @$address_info;
    print OUTPUTFILE $firstname."|".$lastname."|".$street."|".$city."|".$STATE;
    $dbh->commit();
    $dbh->disconnect();
    close OUTPUTFILE;
    Thanks!
    rulin

    Thanks for you reply!
    1) The stored procedure has head
    CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    cv_1 IN OUT SYS_REFCURSOR
    AS
    err_msg VARCHAR2(100);
    BEGIN
    --Adaptive Server has expanded all '*' elements in the following statement
    OPEN cv_1 FOR
    Select ...
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    err_msg := SQLERRM;
    dbms_output.put_line (err_msg);
    ROLLBACK;
    END;
    If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
    2) But when call stored procedure, it will take 80-100 minutes .
    3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
    CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    AS
    BEGIN
    select ..
    The select part is exact same.
    4) The perl code is almost exact same, except the query sql:
    sybase verson: my $sql ="exec DISPLAY_ADDRESS";
    and no need bind the cursor parameter.
    This is batch job, we create a file with all information, and ftp to clients everynight.
    Thanks!
    Rulin

  • Java stored procedures performance ....

    I am currently evaluating the use of Java stored procedures, but
    have so far found the performance to be incredibly poor. If I
    write a simple piece of SQL to insert 1 row to a 2 column table
    via a standalone JDBC application, the average elapsed time over
    5 runs is approx 24 milliseconds. If I move the same piece of
    code to a Java stored procedure, the elapsed time increases (on
    average) to 28 seconds ! Surely this shouldn't be the case; I
    had expected the performance to increase rather than plummet as
    is the case. The DBA team cannot find anything amiss in the
    database, & we are basically scratching our heads as to what the
    problem is. Is there something fundamental that needs to be done
    the database for a Java implementation ??
    ANY IDEAS ANYONE ???????
    nb: database ver 8.1.5, running on Solaris 5.7
    regards,
    Paul.
    null

    Try running long queries. In 8.1.6, we are concentrating more
    on increasing the performance of JDBC driver inside the server.
    Paul Jones (guest) wrote:
    : I am currently evaluating the use of Java stored procedures,
    but
    : have so far found the performance to be incredibly poor. If I
    : write a simple piece of SQL to insert 1 row to a 2 column table
    : via a standalone JDBC application, the average elapsed time
    over
    : 5 runs is approx 24 milliseconds. If I move the same piece of
    : code to a Java stored procedure, the elapsed time increases (on
    : average) to 28 seconds ! Surely this shouldn't be the case; I
    : had expected the performance to increase rather than plummet as
    : is the case. The DBA team cannot find anything amiss in the
    : database, & we are basically scratching our heads as to what
    the
    : problem is. Is there something fundamental that needs to be
    done
    : the database for a Java implementation ??
    : ANY IDEAS ANYONE ???????
    : nb: database ver 8.1.5, running on Solaris 5.7
    : regards,
    : Paul.
    Oracle Technology Network
    http://technet.oracle.com
    null

Maybe you are looking for

  • How do I get the images to show up in bridge

    How do I get the cr2 thumbnails to go away so that I can view my images?

  • I cannot install itunes on my acer espire windows 8 laptop

    I have just bought a new Acer espier laptop with windows 8 installed on it. and I have tried multiple times to install iTunes already and it has failed to install. I go to the iTunes website to look for the download link. which takes me to a button t

  • Why does iTunes corrupting my music files!??

    Ok its been a week since I've gone out an bought myself a well 160gb iPod Classic, looks fantastic and have used mates iPods before with no problem. A week later... I've been pulling my hair out.. not good at my age. Every song I play in iTunes (any

  • Kernel-2.6.20-1

    hi, i just did a pacman -Suy and it upgraded my system and everything is working great so far. now when i try to compile a module for a dvb adapter i get "Could not identify kernel" when i do uname -r it splits back 2.6.20-ARCH   in /usr/src/  i have

  • Wow, faster speeds thanks to you guys! But I could...

    Hi, Me again. I would just like to say thank you to everyone here who helped me out. I bought a BT Business hub and my speed has rocketed. My line capacity was at around 650-750kbps, now I'm topping 950kbps, which means I went up a profile! This mean