How to tune the code

Hello experts!
We have a report, which always fails, because it query huge tables and then union them together. I was wondering if u can advice another approach, may be use PL/SQL instead of SQL. The query as is:
CREATE OR REPLACE PROCEDURE PRC_BATCH227E_RPT(myPointer IN OUT PKGREPORTS.ReportDataType)
As
BEGIN
OPEN myPointer FOR
SELECT id, id2, touserid,mpi_network_code, savings_flg, NVL(claims, 0) claims,charges, allowed_charges, savings
FROM(
SELECT
1 id2,
CASE WHEN TO_NUMBER(routingcode) = 710 AND cr.touserid <> 'GCS' THEN cr.touserid
WHEN TO_NUMBER(routingcode) = 712 THEN cr.touserid
ELSE 'MP' END touserid,
'' mpi_network_code,
'' savings_flg,
COUNT(ehc.edp_claim_id) claims,
0 charges,
0 allowed_charges,
MAX(TRUNC(sysdate) - TO_DATE(ehc.date_sent,'mmddyyyy')) savings
FROM
mpiefp.edp_hcfa_claim@archive ehc,
reprice.clmrouting@archive cr
WHERE
ehc.alternate_acct_id IN ('2316000000')
AND ehc.status_code > '0'
AND ehc.status_code < '600000000'
AND cr.claimnumber(+) = ehc.rims_claim_number
AND cr.ownerid(+) = 21
AND (cr.seqnumber = (SELECT MAX(seqnumber)
FROM reprice.clmrouting@archive
WHERE claimnumber = cr.claimnumber
AND ownerid = cr.ownerid
OR cr.seqnumber IS NULL)
GROUP BY CASE WHEN TO_NUMBER(routingcode) = 710 AND cr.touserid <> 'GCS' THEN cr.touserid
WHEN TO_NUMBER(routingcode) = 712 THEN cr.touserid
ELSE 'MP' END) t1
FULL JOIN (SELECT 1 id FROM dual)     t2 ON t1.id2 = t2.id
UNION ALL
--Capture those claims that were received today from Great West
SELECT id, id2, touserid,mpi_network_code, savings_flg, NVL(claims, 0) claims,charges, allowed_charges, savings
FROM(
SELECT
2 id2,
'' touserid,
'' mpi_network_code,
'' savings_flg,
SUM(DECODE(edp_claim_id, NULL, 0, 1)) charges,
SUM(CASE WHEN TRUNC(ehc.status_code) >= 200000000 AND TRUNC(ehc.status_code) < 300000000
AND SUBSTR(TO_CHAR(ehc.status_code), -1) = '6' THEN DECODE(edp_claim_id, NULL, 0, 1)
ELSE 0 END) claims,
0 allowed_charges,
0 savings
FROM
mpiefp.edp_hcfa_process_ctl@archive hpc,
mpiefp.edp_hcfa_claim@archive ehc
WHERE
ehc.alternate_acct_id IN ('2316000000')
AND ehc.status_code >='200000000'
AND ehc.status_code <= '970000000'
AND hpc.edp_hcfa_proc_ctl_pk = ehc.edp_hcfa_proc_ctl_key
AND hpc.edp_hcfa_proc_ctl_dt_stamp >= TRUNC(sysdate)) t1
FULL JOIN (SELECT 2 id FROM dual)     t2 ON t1.id2 = t2.id
UNION ALL
--Capture those claims that were returned to GW on previous business day
--and identify which were Vendor claims.
SELECT id, id2, touserid,mpi_network_code, savings_flg, NVL(claims, 0) claims,charges, allowed_charges, savings
FROM(
SELECT /*+ index(EHC IDX$EDP_hcfa_CLAIM$OUTBATCHDT)*/
3 id2,
'' touserid,
DECODE(ehc.mpi_network_code,NULL,'MP',200,'FNX',417,'TRPN',201,'PVS',150,'GCS',250, 'NCN',517, 'TC3',537,'NHBC', 'MP') mpi_network_code,
'' savings_flg,
NVL(COUNT(*), 0) claims,
0 charges,
0 allowed_charges,
0 savings
FROM
mpiefp.edp_hcfa_claim@archive ehc
WHERE
ehc.outbatch_date >= TRUNC(sysdate-1)
AND ehc.outbatch_date < TRUNC(sysdate)
AND ehc.alternate_acct_id in ('2316000000')
AND ehc.status_code >='600000000'
AND ehc.status_code <= '700000000'
GROUP BY DECODE(ehc.mpi_network_code,NULL,'MP',200,'FNX',417,'TRPN',201,'PVS',150,'GCS',250, 'NCN',517, 'TC3',537,'NHBC','MP')) t1
FULL JOIN (SELECT 3 id FROM dual)     t2 ON t1.id2 = t2.id
UNION ALL
--Capture those claims that were sent to Vendor today.
SELECT id, id2, touserid,mpi_network_code, savings_flg, NVL(claims, 0) claims,charges, allowed_charges, savings
FROM(
SELECT /*+ index (cr, IDX2_CLMROUTING) leading(cr) */
4 id2,
DECODE(touserid, 'BCE', 'FNX',touserid) touserid,
'' mpi_network_code,
'' savings_flg,
NVL(COUNT(*), 0) claims,
SUM(ehc.claim_total_charge) charges,
0 allowed_charges,
0 savings
FROM
mpiefp.edp_hcfa_claim@archive ehc,
reprice.clmrouting@archive cr
WHERE
ehc.alternate_acct_id IN ('2316000000')
AND ehc.status_code >= '400000000'
AND ehc.status_code <= '700000000'
AND cr.claimnumber = ehc.rims_claim_number
AND cr.ownerid(+) = 21
AND cr.routingcode = 712
AND cr.routingtime >= TRUNC(sysdate)
AND ((cr.fromuserid = 'GCS' AND cr.touserid = 'GCS') OR
(cr.fromuserid = 'BCE' AND cr.touserid = 'BCE') OR
(cr.fromuserid = 'NCN' AND cr.touserid = 'NCN') OR
(cr.fromuserid = 'PVS' AND cr.touserid = 'PVS') OR
(cr.fromuserid = 'TC3' AND cr.touserid = 'TC3') OR
(cr.fromuserid = 'TRPN' AND cr.touserid = 'TRPN') OR
(cr.fromuserid = 'MPIEDI - HCFA' AND cr.touserid = 'FNX INBOUND') OR
(cr.fromuserid = 'FNX INBOUND' AND cr.touserid = 'FNX INBOUND') OR
(cr.fromuserid = 'NHBC' AND cr.touserid = 'NHBC'))
GROUP BY touserid     ) t1
FULL JOIN (SELECT 4 id FROM dual)     t2 ON t1.id2 = t2.id
UNION ALL
SELECT id, id2, touserid,mpi_network_code, savings_flg, NVL(claims, 0) claims,charges, allowed_charges, savings
FROM(
SELECT
5 id2,
CASE WHEN TO_NUMBER(routingcode) = 710 AND cr.touserid <> 'GCS' THEN cr.touserid
WHEN TO_NUMBER(routingcode) = 712 THEN cr.touserid
WHEN cr.touserid = 'BCE' THEN 'FNX'
ELSE 'MP' END touserid,
'' mpi_network_code,
'' savings_flg,
COUNT(ehc.edp_claim_id) claims,
0 charges,
0 allowed_charges,
MAX(TRUNC(sysdate) - TO_DATE(ehc.date_sent,'mmddyyyy')-1) savings
FROM
mpiefp.edp_hcfa_claim@archive ehc,
reprice.clmrouting@archive cr
WHERE
ehc.alternate_acct_id IN ('2316000000')
AND ehc.status_code BETWEEN '400000000' AND '600000000'
AND cr.ownerid = 21
AND cr.claimnumber = ehc.rims_claim_number
AND cr.seqnumber = (SELECT MAX(seqnumber)
FROM reprice.clmrouting@archive
WHERE claimnumber = cr.claimnumber
AND ownerid = cr.ownerid
AND cr.routingcode IN (712,710)
AND cr.touserid IN ('GCS','BCE', 'NCN','PVS', 'TC3','NHBC','FNX INBOUND')
GROUP BY CASE WHEN TO_NUMBER(routingcode) = 710 AND cr.touserid <> 'GCS' THEN cr.touserid
WHEN TO_NUMBER(routingcode) = 712 THEN cr.touserid
WHEN cr.touserid = 'BCE' THEN 'FNX'
ELSE 'MP' END) t1
FULL JOIN (SELECT 5 id FROM dual)     t2 ON t1.id2 = t2.id
UNION ALL
--SUMMARY OF RETURN FILE SHOWING MultiPlan and Vendor Claims with/without savings.
SELECT id, id2, touserid,mpi_network_code, savings_flg, NVL(claims, 0) claims,charges, allowed_charges, savings
FROM(
SELECT /*+ index(EHC IDX$EDP_hcfa_CLAIM$OUTBATCHDT)*/
8 id2,
'' touserid,
DECODE(ehc.mpi_network_code,NULL,'MP',200,'FNX',201,'PVS',150,'GCS',250, 'NCN',517, 'TC3',537,'NHBC','MP') mpi_network_code,
DECODE(ehc.savings,0,'NOSAVINGS',NULL,'NOSAVINGS','SAVINGS') savings_flg,
NVL(COUNT(ehc.edp_claim_id), 0) claims,
SUM(ehc.claim_total_charge) charges,
SUM(ehc.allowed_amt) allowed_charges,
SUM(ehc.savings) savings
FROM
mpiefp.edp_hcfa_claim@archive ehc
WHERE
ehc.outbatch_date >= TRUNC(sysdate-1)
AND ehc.outbatch_date < TRUNC(sysdate)
AND ehc.alternate_acct_id IN ('2316000000')
AND ehc.status_code > '600000000'
AND ehc.status_code < '700000000'
GROUP BY
DECODE(ehc.savings,0,'NOSAVINGS',NULL,'NOSAVINGS','SAVINGS'),
DECODE(ehc.mpi_network_code,NULL,'MP',200,'FNX',201,'PVS',150,'GCS',250,'NCN',517, 'TC3',537,'NHBC','MP')) t1
FULL JOIN (SELECT 8 id FROM dual)     t2 ON t1.id2 = t2.id;
EXCEPTION
WHEN OTHERS THEN
RETURN;
END PRC_BATCH227E_RPT;
/

may be use PL/SQL instead of SQL. If your SQL sucks replacing it with PL/SQL is only going to make things worse.
I was wondering if u can advice Well, I got some questions, I hope they'll do.
(1) All these tables are on a remote database. Why not run the report there? Because it is a very very very bad idea to query huge tables across a database link.
(2) What is the point of all the
FULL JOIN (SELECT 1 id FROM dual) t2 ON t1.id2 = t2.idconstructs? Other than cluttering up the code and putting additional strain on the system that is.
Beyond that you need to read Rob Van Wijk's excellent post When your query takes too long ....
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/

Similar Messages

  • How to tune plsql code

    hi all,
    tell me any one how to tune the plsql code in oracle plsql

    You could have googled a bit ->
    http://www.google.co.in/#hl=en&q=tuning+pl+sql+in+oracle&meta=&aq=&oq=tuning+pl+sql+in+oracle&fp=3c5f05f17abf6d93
    Regards.
    Satyaki De.

  • How to tune the Update statement for 20 million rows

    Hi,
    I want to update 20 million rows of a table. I wrote the PL/SQL code like this:
    DECLARE
    v1
    v2
    cursor C1 is
    select ....
    BEGIN
    Open C1;
    loop
    fetch C1 bulk collect into v1,v2 LIMIT 1000
    exit when C1%NOTFOUND;
    forall i in v1.first..v1.last
    update /*+INDEX(tab indx)*/....
    end loop;
    commit;
    close C1;
    END;
    The above code took 24 mins to update 100k records, so for around 20 million records it will take 4800 mins (80 hrs).
    How can I tune the code further ? Will a simple Update statement, instead of PL/SQL make the update faster ?
    Will adding few more hints help ?
    Thanks for your suggestions.
    Regards,
    Yogini Joshi

    Hello
    You have implemented this update in the slowest possible way. Cursor FOR loops should be absolute last resort. If you post the SQL in your cursor there is a very good chance we can re-code it to be a single update statement with a subquery which will be the fastest possible way to run this. Please remember to use the {noformat}{noformat} tags before and after your code so the formatting is preserved.
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to write the code to send the report output to the local file.

    dear all,
    how to write the code to send the report output to the local file.
    Thanks & Regards,
    Jyothi.

    Hi,
    Try this , it will display report and download the file as well. Just vhange the path and execute
    TYPE-POOLS : SLIS.
    DATA : IT_SCARR TYPE TABLE OF SCARR,
           IT_FCAT  TYPE SLIS_T_FIELDCAT_ALV.
    SELECT *
    FROM SCARR
    INTO TABLE IT_SCARR.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    *   I_PROGRAM_NAME               =
    *   I_INTERNAL_TABNAME           =
        I_STRUCTURE_NAME             = 'SCARR'
    *   I_CLIENT_NEVER_DISPLAY       = 'X'
    *   I_INCLNAME                   =
    *   I_BYPASSING_BUFFER           =
    *   I_BUFFER_ACTIVE              =
      CHANGING
        CT_FIELDCAT                  = IT_FCAT
    * EXCEPTIONS
    *   INCONSISTENT_INTERFACE       = 1
    *   PROGRAM_ERROR                = 2
    *   OTHERS                       = 3
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    *   I_INTERFACE_CHECK              = ' '
    *   I_BYPASSING_BUFFER             =
    *   I_BUFFER_ACTIVE                = ' '
    *   I_CALLBACK_PROGRAM             = ' '
    *   I_CALLBACK_PF_STATUS_SET       = ' '
    *   I_CALLBACK_USER_COMMAND        = ' '
    *   I_STRUCTURE_NAME               =
    *   IS_LAYOUT                      =
       IT_FIELDCAT                    = IT_FCAT
    *   IT_EXCLUDING                   =
    *   IT_SPECIAL_GROUPS              =
    *   IT_SORT                        =
    *   IT_FILTER                      =
    *   IS_SEL_HIDE                    =
    *   I_DEFAULT                      = 'X'
    *   I_SAVE                         = ' '
    *   IS_VARIANT                     =
    *   IT_EVENTS                      =
    *   IT_EVENT_EXIT                  =
    *   IS_PRINT                       =
    *   IS_REPREP_ID                   =
    *   I_SCREEN_START_COLUMN          = 0
    *   I_SCREEN_START_LINE            = 0
    *   I_SCREEN_END_COLUMN            = 0
    *   I_SCREEN_END_LINE              = 0
    *   IR_SALV_LIST_ADAPTER           =
    *   IT_EXCEPT_QINFO                =
    *   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
    * IMPORTING
    *   E_EXIT_CAUSED_BY_CALLER        =
    *   ES_EXIT_CAUSED_BY_USER         =
      TABLES
        T_OUTTAB                       = IT_SCARR
    * EXCEPTIONS
    *   PROGRAM_ERROR                  = 1
    *   OTHERS                         = 2
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
      EXPORTING
    *    BIN_FILESIZE              =
        FILENAME                  = 'C:\Documents and Settings\sap\Desktop\Hi.xls' " Change path
    *    FILETYPE                  = 'ASC'
    *    APPEND                    = SPACE
    *    WRITE_FIELD_SEPARATOR     = SPACE
    *    HEADER                    = '00'
    *    TRUNC_TRAILING_BLANKS     = SPACE
    *    WRITE_LF                  = 'X'
    *    COL_SELECT                = SPACE
    *    COL_SELECT_MASK           = SPACE
    *    DAT_MODE                  = SPACE
    *    CONFIRM_OVERWRITE         = SPACE
    *    NO_AUTH_CHECK             = SPACE
    *    CODEPAGE                  = SPACE
    *    IGNORE_CERR               = ABAP_TRUE
    *    REPLACEMENT               = '#'
    *    WRITE_BOM                 = SPACE
    *    TRUNC_TRAILING_BLANKS_EOL = 'X'
    *  IMPORTING
    *    FILELENGTH                =
      CHANGING
        DATA_TAB                  = IT_SCARR
    *  EXCEPTIONS
    *    FILE_WRITE_ERROR          = 1
    *    NO_BATCH                  = 2
    *    GUI_REFUSE_FILETRANSFER   = 3
    *    INVALID_TYPE              = 4
    *    NO_AUTHORITY              = 5
    *    UNKNOWN_ERROR             = 6
    *    HEADER_NOT_ALLOWED        = 7
    *    SEPARATOR_NOT_ALLOWED     = 8
    *    FILESIZE_NOT_ALLOWED      = 9
    *    HEADER_TOO_LONG           = 10
    *    DP_ERROR_CREATE           = 11
    *    DP_ERROR_SEND             = 12
    *    DP_ERROR_WRITE            = 13
    *    UNKNOWN_DP_ERROR          = 14
    *    ACCESS_DENIED             = 15
    *    DP_OUT_OF_MEMORY          = 16
    *    DISK_FULL                 = 17
    *    DP_TIMEOUT                = 18
    *    FILE_NOT_FOUND            = 19
    *    DATAPROVIDER_EXCEPTION    = 20
    *    CONTROL_FLUSH_ERROR       = 21
    *    NOT_SUPPORTED_BY_GUI      = 22
    *    ERROR_NO_GUI              = 23
    *    others                    = 24
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
      EXPORTING
        DOCUMENT               = 'C:\Documents and Settings\sap\Desktop\Hi.xls' "Change path
    *    APPLICATION            =
    *    PARAMETER              =
    *    DEFAULT_DIRECTORY      =
    *    MAXIMIZED              =
    *    MINIMIZED              =
    *    SYNCHRONOUS            =
    *    OPERATION              = 'OPEN'
    *  EXCEPTIONS
    *    CNTL_ERROR             = 1
    *    ERROR_NO_GUI           = 2
    *    BAD_PARAMETER          = 3
    *    FILE_NOT_FOUND         = 4
    *    PATH_NOT_FOUND         = 5
    *    FILE_EXTENSION_UNKNOWN = 6
    *    ERROR_EXECUTE_FAILED   = 7
    *    SYNCHRONOUS_FAILED     = 8
    *    NOT_SUPPORTED_BY_GUI   = 9
    *    others                 = 10
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • How to prevent the code viewing of jsp files

    hello friends
    How to prevent the code viewing on directly opening .jsp files at the server side
    Thanks in advance

    hello friends
    How to prevent the code viewing on directly opening
    .jsp files at the server side
    Thanks in advanceWhat exactly do you mean by code viewing? If by that you mean you don't want all the folders to show in the directory create a index.jsp file that has all the links to the pages you want to show
    If you mean something else please clarify

  • How to Tune the Transactions/ Z - reports /Progr..of High response time

    Dear friends,
    in <b>ST03</b> work load anlysis menu.... there are some z-reports, transactions, and some programmes are noticed contineously that they are taking the <b>max. response time</b> (and mostly >90%of time is  DB Time ).
    how to tune the above situation ??
    Thank u.

    Siva,
    You can start with some thing like:
    ST04  -> Detail Analysis -> SQL Request (look at top disk reads and buffer get SQL statements)
    For the top SQL statements identified you'd want to look at the explain plan to determine if the SQL statements is:
    1) inefficient
    2) are your DB stats up to date on the tables (note up to date stats does not always means they are the best)
    3) if there are better indexes available, if not would a more suitable index help?
    4) if there are many slow disk reads, is there an I/O issue?
    etc...
    While you're in ST04 make sure your buffers are sized adequately.
    Also make sure your Oracle parameters are set according to this OSS note.
    Note 830576 - Parameter recommendations for Oracle 10g

  • How to read the code of html page

    Hi,
    I want to know how to read the code of html page through Java? And if anyone know the link of full implementation of Page Rank Algorithm in Java.
    Please let me know. I have to do the project on that topic.
    Regard
    Vivek

    Vivek_NITT wrote:
    I want to know how to read the code of html page through Java? Get the input stream from an HttpUrlConnection. Read from it like from any other stream.
    And if anyone know the link of full implementation of Page Rank Algorithm in Java.Which one?

  • How to tune the follwoing procedure?

    create or replace procedure sample(verror_msg in out varchar2,
    vbrn_num in tb_branches.brn_num%type) is
    ltext1 varchar2(500);
    ltext2 varchar2(500);
    ltable_name varchar2(50);
    lcolumn_name varchar2(50);
    ldata_type varchar2(50);
    lold_rcn_num number;
    lnew_rcn_num number;
    lvalue varchar2(50);
    lunit_type char(1);
    lsql_stmt1 varchar2(500);
    lstring varchar2(500);
    lcol varchar2(10);
    lstart_time VARCHAR2(100);
    lend_time VARCHAR2(100);
    lcommit VARCHAR2(10) := 'COMMIT;';
    lfile_handle1 utl_file.file_type;
    lfile_handle2 utl_file.file_type;
    lfile_handle3 utl_file.file_type;
    lfile_handle4 utl_file.file_type;
    lfile_name1 VARCHAR2(50) := 'RCN_UPDATE_STMTS_' || vbrn_num || '.SQL';
    lfile_name2 VARCHAR2(50) := 'RCNSUCCESS_' || vbrn_num || '.TXT';
    lfile_name3 VARCHAR2(50) := 'RCNFAIL_' || vbrn_num || '.TXT';
    lfile_name4 VARCHAR2(50) := 'RCNERROR_' || vbrn_num || '.TXT';
    ldirectory_name VARCHAR2(100);
    ldirectory_path VARCHAR2(100);
    lspool_on VARCHAR2(100);
    lspool_off VARCHAR2(100);
    TYPE ref_cur IS REF CURSOR;
    cur_tab_cols ref_cur;
    cursor c1 is
    SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
    FROM USER_TAB_COLS
    WHERE TABLE_NAME NOT LIKE 'TB_CONV%'
    and TABLE_NAME LIKE 'TB_%'
    AND COLUMN_NAME LIKE '%RCN%'
    UNION
    SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
    FROM USER_TAB_COLS
    WHERE TABLE_NAME in ('TB_UNITCODES', 'TB_HIST_UNITCODES')
    AND COLUMN_NAME = 'UNIT_CODE'
    order by table_name;
    BEGIN
    verror_msg := nvl(verror_msg, 0);
    begin
    SELECT DISTINCT directory_path, directory_name
    INTO ldirectory_path, ldirectory_name
    FROM tb_conv_path
    WHERE brn_num = vbrn_num;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    SP_CO_RAISEERROR('00SY00402', 'F', 'T');
    WHEN others THEN
    SP_CO_RAISEERROR('00SY00401X', 'F', 'T');
    END;
    lfile_handle1 := utl_file.fopen(ldirectory_name, lfile_name1, 'W', 32767);
    lfile_handle2 := utl_file.fopen(ldirectory_name, lfile_name2, 'W', 32767);
    lfile_handle3 := utl_file.fopen(ldirectory_name, lfile_name3, 'W', 32767);
    lfile_handle4 := utl_file.fopen(ldirectory_name, lfile_name4, 'W', 32767);
    SELECT 'SPOOL ' || ldirectory_path || '/LOG_' || lfile_name1
    INTO lspool_on
    FROM dual;
    utl_file.put_line(lfile_handle1, lspool_on);
    utl_file.new_line(lfile_handle1, 1);
    select 'EXEC SP_CONV_START_TIMELOG(' || '''' || 'LOG_' || lfile_name1 || '''' || ',' ||
    vbrn_num || ');'
    into lstart_time
    from dual;
    UTL_FILE.PUT_LINE(lfile_handle1, lstart_time);
    UTL_FILE.NEW_LINE(lfile_handle1, 1);
    open C1;
    loop
    Fetch C1
    into ltable_name, lcolumn_name, ldata_type;
    Exit When C1%notFound;
    lsql_stmt1 := 'select column_name from user_tab_columns where table_name =' || '''' ||
    ltable_name || '''' ||
    ' AND column_name in (''BRN_NUM'',''BRANCH'',''BRANCH_NUMBER'')';
    begin
    execute immediate lsql_stmt1
    into lcol;
    exception
    when no_data_found then
    lcol := null;
    end;
    if lcol is not null then
    if ltable_name in ('TB_UNITCODES', 'TB_HIST_UNITCODES') then
    ltext2 := 'select distinct ' || lcolumn_name || ' from ' ||
    ltable_name ||
    ' a, (select distinct new_rcn_num col from tb_conv_rcn_mapping where brn_num = ' ||
    vbrn_num || ') b where a.' || lcolumn_name ||
    ' = b.col(+) and b.col is null and a.' || lcolumn_name ||
    ' is not null and ' || lcol || ' = ' || vbrn_num ||
    ' and a.unit_type=''9''';
    else
    ltext2 := 'select distinct ' || lcolumn_name || ' from ' ||
    ltable_name ||
    ' a, (select distinct new_rcn_num col from tb_conv_rcn_mapping where brn_num = ' ||
    vbrn_num || ') b where a.' || lcolumn_name ||
    ' = b.col(+) and b.col is null and a.' || lcolumn_name ||
    ' is not null and ' || lcol || ' = ' || vbrn_num;
    end if;
    OPEN cur_tab_cols FOR ltext2;
    loop
    fetch cur_tab_cols
    into lvalue;
    exit when cur_tab_cols%notfound;
    begin
    IF VBRN_NUM IN (21, 6, 7, 8) THEN  Commented during NAP HK SIT cycle1
    SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
    INTO LNEW_RCN_NUM, LOLD_RCN_NUM
    FROM TB_CONV_RCN_MAPPING
    WHERE OLD_RCN_NUM = LVALUE
    AND BRN_NUM = VBRN_NUM;
    /* ELSE
    SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
    INTO LNEW_RCN_NUM, LOLD_RCN_NUM
    FROM TB_CONV_RCN_MAPPING
    WHERE OLD_RCN_NUM = LVALUE
    AND NEW_RCN_NUM NOT LIKE '40%'
    AND NEW_RCN_NUM NOT LIKE '41%'
    AND NEW_RCN_NUM NOT LIKE '42%'
    AND NEW_RCN_NUM NOT LIKE '65%'
    AND BRN_NUM = VBRN_NUM;
    END IF; */ -- Commented during NAP HK SIT cycle1
    if ldata_type = 'NUMBER' then
    if ltable_name in ('TB_UNITCODES', 'TB_HIST_UNITCODES') and
    lcolumn_name = 'UNIT_CODE' then
    begin
    select distinct unit_type
    into lunit_type
    from TB_UNITCODES
    where lcol = vbrn_num
    and unit_code = lvalue
    and unit_type = '9';
    exception
    when no_data_found then
    lunit_type := null;
    end;
    if lunit_type is not null then
    ltext1 := 'update ' || ltable_name || ' set ' ||
    lcolumn_name || ' = ' || lnew_rcn_num ||
    ' where ' || lcolumn_name || ' = ' ||
    lold_rcn_num || ' and ' || lcol || ' = ' ||
    vbrn_num || ' and unit_type = ' || '''9''' || ';';
    utl_file.put_line(lfile_handle1, ltext1);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle1, lcommit);
    utl_file.put_line(lfile_handle2,
    ltable_name || ' - ' || lcolumn_name ||
    ' - ' || lold_rcn_num || ' - ' ||
    lnew_rcn_num || ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle2, 0);
    end if;
    else
    ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
    ' = ' || lnew_rcn_num || ' where ' || lcolumn_name ||
    ' = ' || lold_rcn_num || ' and ' || lcol || ' = ' ||
    vbrn_num || ';';
    utl_file.put_line(lfile_handle1, ltext1);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle1, lcommit);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle2,
    ltable_name || ' - ' || lcolumn_name ||
    ' - ' || lold_rcn_num || ' - ' ||
    lnew_rcn_num || ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle2, 0);
    end if;
    else
    if ltable_name in ('TB_UNITCODES', 'TB_HIST_UNITCODES') and
    lcolumn_name = 'UNIT_CODE' then
    begin
    lstring := 'select distinct unit_type from ' || ltable_name ||
    ' where ' || lcol || ' = ' || vbrn_num ||
    ' and ' || lcolumn_name || ' = ' || '''' ||
    lvalue || '''' || ' and unit_type = ' || '''9''';
    execute immediate lstring
    into lunit_type;
    exception
    when no_data_found then
    lunit_type := null;
    end;
    if lunit_type is not null then
    ltext1 := 'update ' || ltable_name || ' set ' ||
    lcolumn_name || ' = ' || '''' || lnew_rcn_num || '''' ||
    ' where ' || lcolumn_name || ' = ' || '''' ||
    lold_rcn_num || '''' || ' and ' || lcol || ' = ' ||
    vbrn_num || ' and unit_type = ' || '''9''' || ';';
    utl_file.put_line(lfile_handle1, ltext1);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle1, lcommit);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle2,
    ltable_name || ' - ' || lcolumn_name ||
    ' - ' || lold_rcn_num || ' - ' ||
    lnew_rcn_num || ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle2, 0);
    end if;
    else
    ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
    ' = ' || '''' || lnew_rcn_num || '''' || ' where ' ||
    lcolumn_name || ' = ' || '''' || lold_rcn_num || '''' ||
    ' and ' || lcol || ' = ' || vbrn_num || ';';
    utl_file.put_line(lfile_handle1, ltext1);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle1, lcommit);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle2,
    ltable_name || ' - ' || lcolumn_name ||
    ' - ' || lold_rcn_num || ' - ' ||
    lnew_rcn_num || ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle2, 0);
    end if;
    end if;
    exception
    When NO_DATA_FOUND THEN
    utl_file.put_line(lfile_handle3,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lvalue || ' - ' || 'NO MAPPING FOUND' ||
    ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle3, 0);
    when others then
    utl_file.put_line(lfile_handle4,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lvalue || ' - ' || SQLERRM || ' - ' ||
    vbrn_num);
    utl_file.new_line(lfile_handle4, 0);
    end;
    end loop;
    ELSE
    ltext2 := 'select distinct ' || lcolumn_name || ' from ' ||
    ltable_name ||
    ' a, (select distinct new_rcn_num col from tb_conv_rcn_mapping where brn_num = ' ||
    vbrn_num || ') b where a.' || lcolumn_name ||
    ' = b.col(+) and b.col is null and a.' || lcolumn_name ||
    ' is not null';
    OPEN cur_tab_cols FOR ltext2;
    loop
    fetch cur_tab_cols
    into lvalue;
    exit when cur_tab_cols%notfound;
    begin
    IF VBRN_NUM IN (21, 6, 7, 8) THEN  Commented during NAP HK SIT cycle1
    SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
    INTO LNEW_RCN_NUM, LOLD_RCN_NUM
    FROM TB_CONV_RCN_MAPPING
    WHERE OLD_RCN_NUM = LVALUE
    AND BRN_NUM = VBRN_NUM;
    /* ELSE
    SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
    INTO LNEW_RCN_NUM, LOLD_RCN_NUM
    FROM TB_CONV_RCN_MAPPING
    WHERE OLD_RCN_NUM = LVALUE
    AND NEW_RCN_NUM NOT LIKE '40%'
    AND NEW_RCN_NUM NOT LIKE '41%'
    AND NEW_RCN_NUM NOT LIKE '42%'
    AND NEW_RCN_NUM NOT LIKE '65%'
    AND BRN_NUM = VBRN_NUM;
    END IF; */ -- Commented during NAP HK SIT cycle1
    if ldata_type = 'NUMBER' then
    ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
    ' = ' || lnew_rcn_num || ' where ' || lcolumn_name ||
    ' = ' || lold_rcn_num || ';';
    utl_file.put_line(lfile_handle1, ltext1);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle1, lcommit);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle2,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lold_rcn_num || ' - ' || lnew_rcn_num ||
    ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle2, 0);
    else
    ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
    ' = ' || '''' || lnew_rcn_num || '''' || ' where ' ||
    lcolumn_name || ' = ' || '''' || lold_rcn_num || '''' || ';';
    utl_file.put_line(lfile_handle1, ltext1);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle1, lcommit);
    utl_file.new_line(lfile_handle1, 0);
    utl_file.put_line(lfile_handle2,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lold_rcn_num || ' - ' || lnew_rcn_num ||
    ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle2, 0);
    end if;
    exception
    When NO_DATA_FOUND THEN
    utl_file.put_line(lfile_handle3,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lvalue || ' - ' || 'NO MAPPING FOUND' ||
    ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle3, 0);
    when others then
    utl_file.put_line(lfile_handle4,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lvalue || ' - ' || SQLERRM || ' - ' ||
    vbrn_num);
    utl_file.new_line(lfile_handle4, 0);
    end;
    end loop;
    end if;
    end loop;
    close c1;
    utl_file.new_line(lfile_handle1, 1);
    select 'EXEC SP_CONV_END_TIMELOG(' || '''' || 'LOG_' || lfile_name1 || '''' || ',' ||
    vbrn_num || ');'
    into lend_time
    from dual;
    UTL_FILE.PUT_LINE(lfile_handle1, lend_time);
    UTL_FILE.NEW_LINE(lfile_handle1, 1);
    SELECT 'SPOOL OFF;' INTO lspool_off FROM dual;
    utl_file.put_line(lfile_handle1, lspool_off);
    utl_file.new_line(lfile_handle1, 1);
    utl_file.fclose(lfile_handle1);
    utl_file.fclose(lfile_handle2);
    utl_file.fclose(lfile_handle3);
    utl_file.fclose(lfile_handle4);
    exception
    when others then
    verror_msg := sqlcode || ' ~ ' || sqlerrm;
    utl_file.put_line(lfile_handle4,
    ltable_name || ' - ' || lcolumn_name || ' - ' ||
    lvalue || ' - ' || SQLERRM || ' - ' || vbrn_num);
    utl_file.new_line(lfile_handle4, 0);
    utl_file.new_line(lfile_handle4, 0);
    utl_file.fclose(lfile_handle1);
    utl_file.fclose(lfile_handle2);
    utl_file.fclose(lfile_handle3);
    utl_file.fclose(lfile_handle4);
    end sample;

    duplicate:
    how to tune the follwoing procedure?

  • LSMW VD51 , Validations in Begin of Transaction; how to Debug the code?

    Hi All,
    I have written code for validations i Begin of Transaction in the field mapping 5th step of LSMW for VD51.
    Now this code not getting triggered at the time of Conversion of Data. How to debug the code. I have put a static break point 'BREAK-POINT' still not getting triggered.
    Any suggestion / solution for this issue.
    Thanks and Regards,
    Narsimha Kulkarni

    Hi Narshimha,
    Make any mapping error during mapping and check the syntax of mapping it will drag you to the lsmw report there you can put your break point. You can check the report name from transaction code as well.
    Remember this mapping block will execute when you execute the step Convert Data in LSMW.
    Regards
    Dhirendra

  • How to modify the code???

    Hello forum,
    I have code for retriving data from database.
    I want to retrieve more than one row but the code only retrive the
    last row. How to mdify the code??? SorryI am new in Servlet and JDBC.
    Here is the codeimport java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class TiketServlet extends HttpServlet {
         static final String dbURL ="jdbc:mysql://localhost:3306/tiketdb?" + "user=firman&password=ajolie";
         StringBuffer fullName = new StringBuffer();
         public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws IOException, ServletException {
         Connection conn = null;
         String nextJSP = null;
         try {
              Class.forName("com.mysql.jdbc.Driver");
         catch (ClassNotFoundException e) {
              throw new ServletException("Unable to load JDBC driver");
         try {
         String keretaID = (String)request.getParameter("keretaID");
         String kelas = (String)request.getParameter("kelas");
              conn = DriverManager.getConnection(dbURL);
              Statement stmt1 = conn.createStatement();
              String query1 = "SELECT gerbong, kursi FROM "+keretaID+" WHERE kelas ='"+kelas+"';";
              ResultSet rs1 = stmt1.executeQuery(query1);
              while (rs1.next()) {
                   StringBuffer fullName = new StringBuffer();
                   fullName.append(rs1.getString(1));
                   fullName.append(" ");
                   fullName.append(rs1.getString(2));
                   fullName.append('\n');
                   request.setAttribute ("fullName", fullName.toString());
                   nextJSP = "/LoginOK.jsp";
              conn.close();
              ServletConfig config = getServletConfig();
              ServletContext context = config.getServletContext();
              RequestDispatcher rd = context.getRequestDispatcher(nextJSP);
              rd.forward(request, response);
         catch (SQLException e) {
              throw new ServletException(e.getMessage());
         finally {
              if (conn != null) {
                   try {
                        conn.close();
                   catch (SQLException e) {
                        throw new ServletException("connection close failed");
         public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws IOException, ServletException {
                   doPost(request, response);
    Many thanks

    u've to define the stringBuffer before while loop.. thats it u get it correctly..
    b'cos u r defining the stringBuffer inside.. each time when it is entering the loop the the existing stringBuffer is replacing by the new empty stringBuffer...
    --veeru                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to run the code generator

    I urgently need to know how to run the code generator using creator. Can anyone assist? I cant find any tips in the forums.

    I am following the procedure to create a new custom component (or extend an existing component) available at http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/writing_custom_components.html.
    Part of the procedure says: you need to use the JSC to run the code generator based on sun-faces-config.xml metadata.

  • How to know the code error diagnostic hardware (AHT) ?

    I want konw
    How to know the code error when do it Apple Hardware Test.
    Anybody have note the code error (AHT)
    Thank you

    Does this help: http://reviews.cnet.com/8301-13727_7-57352461-263/how-to-invoke-and-interpret-th e-apple-hardware-tests/ ?

  • HT1688 i got the unlock code from at&t but i don't know how to input the code on the phone to unlock the iphone 4s

    i got the unlock code from at&t but i don't know how to input the code on the phone to unlock the iphone 4s

    There is no "unlock code". If you legitimately unlocked your iPhone via ATT, you will get an email detaling the unlock process, which involves connecting to iTunes. Follow the directions in the email.
    If you used one of those web sites that promise an magical "unlock code" you probably got scammed.

  • How to tune the query...?

    Hi all,
    I am having a table with millions of records and the query is taking hours
    time. How to tune the query apart from doing the following things.
    1. Creating or Deleting indexes.
    2. Using Bind variables.
    3. Using Hints.
    4. Updating the Statitics regurarly.
    Actually, i have asked this question in interview how to tune the query.
    I told him the above 4 things. Then he told, these are not working, then
    how you will tune this query.
    Thanks in advance,
    Pal

    user546710 wrote:
    Actually, i have asked this question in interview how to tune the query.
    I told him the above 4 things. Then he told, these are not working, then
    how you will tune this query.It actually depends on the scenario/problem given.
    You may want to read this first.
    When your query takes too long ...
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • How can i know how to redeem the code? how can i get this code?

    how can i know how to redeem the code? how can i get this code? please i need you help
    <Email Edited by Host>

    You are trying to create a new Apple ID? You don't have one yet? Is that correct?
    If so, then see this article on how to creat your Apple ID - and make up a password for it. Remember to write it down immediately.
    http://support.apple.com/en-us/HT203993

Maybe you are looking for

  • Regarding FTP adapter issue

    Hi The below error i am getting using FTP adapter. After deploying the process only one time it is picking the file. But we are putting one more file in that directory it is not read the file. Regarding this cause we are getting the below error. So,a

  • Black spot on the camera

    Two random black spots appeared on my camera display, the phone didn't get wet or anything, seems like dirt from the inside...  should I take it to apple's customers service? anybody with the same problem? thank you

  • PCMCIA-GPIB won't pass Troubleshooting Wizard but Device Mgr reports no conflicts. WIn2000 OS.

    GIPB Interfaces Sequentually verified fails. There are no IRQ or Address conflicts according to the Device Mgr. The Event Viewer says "... event ID (3) in source (gpibtnt) cannot be found. The local computer may not have the necessary registery infor

  • How to save incoming email images?

    I have a Mac desktop running on Lion OS X. When someone sends me an email with photo attachment, how do I save the photo? I tried right clicking the image and in the drop down box I am prompted to either Copy image or Save Attachment. I tried Copy Im

  • Editing multiple ending symbols in score editor...what the heck?!?!?

    I must be dense or something - in ver. 7 lengthening the end bracket on repeated ending symbols was as easy and click-dragging the end to the desired measure. In ver. 8 it appears that there is no editing possible - you're stuck with the default one