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.

Similar Messages

  • How to create plsql code for a snowflake cube

    hi everybody!
    do anyone know how to create plsql code for a snowflake tiype dimension to create
    a cube?how to map the atributes, or if there are any exceptional atributes which I can use like in a temporal dimension?
    thank you
    waiting for any answer

    The DBMS_AWM package provides stored procedures for creating an analytic workspace cube from a star schema. Is it posible to create a cube from a snoflake schema?

  • 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/

  • How to register a custom plsql code

    Hi
    i have wrritten a custom plsql code for my Overtime entries validation for payroll processing.
    Can any body tell me how to register it in application.
    Secondly i want to get the output file generated by report submission on my desktop.i want to know where the report output files for HR and payroll are stored so that i can get them through FTP.
    Regards

    if you want to integrate your plsql into a fast formula, please download the fast formula guide from metalink. Or ask your functional payroll consultant.
    All reports and processes in Oracle Apps are handled via concurrent programs and requests. When a concurrent request is finished, click on the output button, and depending from the filetype, your browser will take action.
    All concurrent output is also stored on the concurrent server. Ask your apps dba where she mapped the concurrent output directory. But i do not see why you should need this.

  • How to call jsp in PLSQL code (to upload a file in IFS)

    Hello,
    We develop our PORTAL (9.0.2) with PL/SQL way.
    We want to make a form to upload file in IFS.
    We create a form like that :
    htp.formOpen(cmethod =>'post',
         cenctype => 'multipart/form-data',
         curl => '/pls/ptlcollab/ptlcollab.GestionDoc_screenbuilder.manipTableIFS',
         cattributes => 'name="ifs"') ;
    htp.TableData(htf.FORMFILE(cname=>'file', cattributes => 'size="25"')) ;
    The manipTableIFS procedure calls a loaded java procedure which called a servlet which work with IFS.
    BUT, modplsql seems to want we directly upload the doc in a table but we want to upload the doc in iFS !!!
    So, the solutiuon seems to call a jsp (or a servlet directly from our plsql code).
    BUT, how could I do that ???
    Any help would be greatly appreciated.
    Regards.
    Luc.

    Something along these lines ought to do what you want:
    <html>
    <body>
    <form name='foobar' action='foobar.jsp'>
    <script language='Javascript'>
    function askim() {
      if (confirm('Is you sure?')) {
        document.foobar.submit();
      } else return false;
    </script>
    <input type='button' value='Submit' onClick='askim()'>
    </form>
    </body>
    </html>
    Your mileage may vary.
    But the idea here is that the Javascript merely submits the form if the user clicks "OK" on the confirmation pop-up. Otherwise, nothing happens. The form is submitted to a JSP file which accepts the request, does something (such as call your Java class), then prints out some HTML in response.

  • How can I have OEM's Metric numbers in PLSQL code?

    Hi,
    I have the following Metric numbers in the web based OEM:
    CPU Used
    Run Queue Length
    Physical Reads (KB)
    Redo Size (KB)
    User I/O
    System I/O
    Network
    Concurrency
    Commit
    I know above Metric numbers come from V$ tables such as: V$SESSION, V$SYSSTAT, V$SESSION_WAIT, V$SYSTEM_EVENT
    Is there anyway that OEM shows me how exactly it gets these numbers, so I can have the very same number in my PLSQL code?
    Thank you,
    Alan

    Hi Justin,
    I just used this query to find the “Run Query Length”:
    select * from v$statname where LOWER(name) like '%queue%'
    It gives me the following result:
    enqueue timeouts     
    enqueue waits     
    enqueue deadlocks     
    enqueue requests     
    enqueue conversions     
    enqueue releases     
    global enqueue gets sync     
    global enqueue gets async     
    global enqueue get time     
    global enqueue releases     
    global enqueue CPU used by this session     
    summed dirty queue length     
    queue update without cp update     
    queue splits     
    queue flush     
    queue position update     
    queue single row     
    queue ocp pages     
    queue qno pages     
    How could I find the relevant rows?
    I am having a similar challenge to find values for “CPU Used” metric
    Thank you,
    Alan

  • How to explicitely write PLSQL code for "Help - Display Error"? [SOLVED]

    I'm using menu DEFAULT&SMARTBAR and I'd like to write command in PLSQL code for "Help - Display Error" to display error. Has anyone any idea how to do this? I can not find syntaks in form help for this.
    Message was edited by:
    marussig

    Display_Error;

  • How to write a file in unix server through oracle plsql code

    Hi All,
    My requirement is to create and write a file (any file for eg txt file) in unix box with in a specified directory through oracle plsql code.
    Oracle sits in windows server.
    using utl_file package we can create directory where oracle resides and write it there in oracle server in our case windows..
    But here we need to create,write a file but in unix server which is different server than where the oracle server resides..
    we are using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    Can any one one please help me out in this issue...
    Thanks in Advance.
    Prakash

    Mr Prakash,
    Why are you asking this question multiple times in every forum you can spell?
    Valid responses have been presented to you already two times.
    Can you explain why you can't follow them up, but continue to abuse this forum by repeating doc questions?
    Sybrand Bakker
    Senior Oracle DBA

  • How to call plsql procedure in jasper

    Hi,
    anybodys know how to call plsql in jasper..
    i have try this code in jasper -> select query langiuage = plsql
    {CALL STD03_MERIT_PROCESSING($P{std03_studentVal},$P{std03_studentVal})}
    but there is error taht said no data found..
    any idea
    Thnak You

    Hi,
    I know nada of Jasper, but it took a couple of seconds to find out that calling stored procedures aren't supported.
    There are number of articles describing work-arounds for that.
    This seems to be a good one:
    http://brianburridge.com/2006/06/04/how-to-call-stored-procedures-from-jasper-reports/
    Other suggests Hibername mappers or some bean approach,
    Regards
    Peter

  • Hide or encrypt password in SQL/PLSQL code

    Hi,
    I need some help or suggestions to hide or encrypt database user password in SQL/PLSQL code. In our environment, we use a connect string with username/password for the JDBC connection. Our goal is to take out the password string and read it or pass it to the code on the fly.
    Thanks,
    Subroto

    So in the database somewhere you are storing username and password credentials? How do those credentials get sent to the Java application? Presumably, the Java application has to connect to the database, requiring a JDBC connection string, in order to query the table in order to get the username and password you've stored in the database.
    Assuming there are two different JDBC connection strings-- one in the Java application that connects to the database and a second that is stored in the database and used later by the Java application, who do you want to protect the data from? Do you want to protect it from other database users? Or do you want to protect it from the Java developers? Or something else?
    Justin

  • How to tune this SQL?

    What this SQL did is to generate a report like how many rows for each tp_stts when ims_toms_msge_type='TOMS NEW' (or 'TOMS CNCLO'). also, its corresponding total number for each ims_toms_msge_type.
    Here is the sample:
    Rownum    H1            TP_STTS                          COUNT        IMS_TOMS_MSGE_TYPE    H   FILTERTYPE
    1     Trades     Block Key Data Error                      594           TOMS NEW             A     MSL
    2          Allocation Data Error                      334           TOMS NEW             A     MSL
    3          Manual Processing Required                29           TOMS NEW             A      MSL
    4          Manual Removal No Processing Required     67           TOMS NEW             A      MSL
    5          Waiting For Authorization                 2            TOMS NEW             A     MSL
    6           Auto NAK                             19764          TOMS NEW             B     SLS
    7           Validated                             165023         TOMS NEW             B     SLS
    8     GRAND TOTAL                                    185813          TOMS NEW              H     MSL
    9     Cancel     Auto NAK                              37             TOMS CNCLO        X       MSL
    10          Manual Processing Required   114                    TOMS CNCLO          X      MSL
    11          Manually Processed              278                   TOMS CNCLO     X     MSL
    12     CANCEL GRAND TOTAL                        429                TOMS CNCLO           Z      MSLSQL statement as below:
    SELECT ROWNUM, MSGS.* FROM (with FTMReport as (
           select tp_stts, ims_toms_msge_type, count(*) count  from ims_trde, ims_toms_msge
                    where  ( IMS_TRDE.PRCSG_GRP_ID  = 5  )  AND  ( IMS_TRDE.IMS_TRDE_RCPT_DTTM  >= TO_DATE('12/01/2009 00:00', 'MM/DD/YYYY HH24:MI') AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <= (TO_DATE('12/28/2009 23:59', 'MM/DD/YYYY HH24:MI'))  )  AND (IMS_TRDE.GRS_TRX_TYPE NOT IN ('INJECTION','WITHDRAWAL','PAYMENT') OR IMS_TRDE.GRS_TRX_TYPE IS NULL) AND (IMS_TRDE.SSC_INVST_TYPE != 'FC' OR IMS_TRDE.SSC_INVST_TYPE IS NULL) AND (IMS_TRDE.SERVICE_TYPE='FS' OR IMS_TRDE.SERVICE_TYPE='CO')  AND 1=1 
        and IMS_TRDE.SERVICE_TYPE='FS'    and  1=1  and ims_trde.ims_trde_oid = ims_toms_msge.ims_trde_oid
           group by tp_stts, ims_toms_msge_type
          select 'GRAND TOTAL' H1,  null tp_stts, sum(Count) count , ims_toms_msge_type ,'H', 'MSL' FilterType
                   from FTMReport  where  ims_toms_msge_type in ('TOMS NEW') group by ims_toms_msge_type
        union
          select 'CANCEL GRAND TOTAL' H1,  null tp_stts, sum(Count) count, ims_toms_msge_type ,'Z', 'MSL' FilterType 
                   from FTMReport where  ims_toms_msge_type in ('TOMS CNCLO') group by ims_toms_msge_type
        union
          select DECODE(rownum, 1, 'Trades') H1, tp_stts, count, ims_toms_msge_type , 'A' , 'MSL' FilterType
                   from FTMReport  where  ims_toms_msge_type in ('TOMS NEW') and tp_stts not in ('Validated','Auto NAK','Manual NAK')
        union
          select ' ' H1, tp_stts, count, ims_toms_msge_type , 'B' , 'SLS' FilterType
                   from FTMReport where  ims_toms_msge_type in ('TOMS NEW') and tp_stts in ('Validated','Auto NAK','Manual NAK')
        union
          select DECODE(rownum, 1, 'Cancel') H1, tp_stts, count, ims_toms_msge_type , 'X' , 'MSL' FilterType
                   from FTMReport where  ims_toms_msge_type in ('TOMS CNCLO') order by 5,6
        ) MSGS;Explain plan as below:
    | Id  | Operation                           |  Name                        | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT                    |                              |   193 | 12738 |    32 |
    |   1 |  COUNT                              |                              |       |       |       |
    |   2 |   VIEW                              |                              |   193 | 12738 |    32 |
    |   4 |    TEMP TABLE TRANSFORMATION        |                              |       |       |       |
    |   3 |     RECURSIVE EXECUTION             | SYS_LE_4_0                   |       |       |       |
    |   0 |      INSERT STATEMENT               |                              |    61 |  4575 |  9264 |
    |   1 |       LOAD AS SELECT                |                              |       |       |       |
    |   2 |        SORT GROUP BY                |                              |    61 |  4575 |  9264 |
    |   3 |         NESTED LOOPS                |                              |  1604 |   117K|  9251 |
    |*  4 |          TABLE ACCESS BY INDEX ROWID| IMS_TRDE                     |  1603 | 80150 |  6045 |
    |*  5 |           INDEX RANGE SCAN          | IMS_TRDE_INDX4               |   539K|       |  3917 |
    |*  6 |          INDEX RANGE SCAN           | IMS_TOMS_MSGE_INDX1          |     1 |    25 |     2 |
    |   5 |     SORT UNIQUE                     |                              |   193 |  8831 |    30 |
    |   6 |      UNION-ALL                      |                              |       |       |       |
    |   7 |       SORT GROUP BY NOSORT          |                              |     5 |   115 |     6 |
    |*  8 |        VIEW                         |                              |    61 |  1403 |     2 |
    |   9 |         TABLE ACCESS FULL           | SYS_TEMP_0FD9D660F_B198D56F  |    61 |  2074 |     2 |
    |  10 |       SORT GROUP BY NOSORT          |                              |     5 |   115 |     6 |
    |* 11 |        VIEW                         |                              |    61 |  1403 |     2 |
    |  12 |         TABLE ACCESS FULL           | SYS_TEMP_0FD9D660F_B198D56F  |    61 |  2074 |     2 |
    |  13 |       COUNT                         |                              |       |       |       |
    |* 14 |        VIEW                         |                              |    61 |  2867 |     2 |
    |  15 |         TABLE ACCESS FULL           | SYS_TEMP_0FD9D660F_B198D56F  |    61 |  2074 |     2 |
    |* 16 |       VIEW                          |                              |    61 |  2867 |     2 |
    |  17 |        TABLE ACCESS FULL            | SYS_TEMP_0FD9D660F_B198D56F  |    61 |  2074 |     2 |
    |  18 |       COUNT                         |                              |       |       |       |
    |* 19 |        VIEW                         |                              |    61 |  2867 |     2 |
    |  20 |         TABLE ACCESS FULL           | SYS_TEMP_0FD9D660F_B198D56F  |    61 |  2074 |     2 |
    Predicate Information (identified by operation id):
       4 - filter(("IMS_TRDE"."GRS_TRX_TYPE"<>'INJECTION' AND "IMS_TRDE"."GRS_TRX_TYPE"<>'WITHDRAWAL'
                  AND "IMS_TRDE"."GRS_TRX_TYPE"<>'PAYMENT' OR "IMS_TRDE"."GRS_TRX_TYPE" IS NULL) AND
                  ("IMS_TRDE"."SSC_INVST_TYPE"<>'FC' OR "IMS_TRDE"."SSC_INVST_TYPE" IS NULL))
       5 - access("IMS_TRDE"."IMS_TRDE_RCPT_DTTM">=TO_DATE(' 2009-12-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "IMS_TRDE"."PRCSG_GRP_ID"=5 AND "IMS_TRDE"."SERVICE_TYPE"='FS' AND
                  "IMS_TRDE"."IMS_TRDE_RCPT_DTTM"<=TO_DATE(' 2009-12-28 23:59:00', 'syyyy-mm-dd hh24:mi:ss'))
           filter("IMS_TRDE"."PRCSG_GRP_ID"=5 AND "IMS_TRDE"."SERVICE_TYPE"='FS')
       6 - access("IMS_TRDE"."IMS_TRDE_OID"="IMS_TOMS_MSGE"."IMS_TRDE_OID")
       8 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW')
      11 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS CNCLO')
      14 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW' AND "FTMREPORT"."TP_STTS"<>'Validated'
                  AND "FTMREPORT"."TP_STTS"<>'Auto NAK' AND "FTMREPORT"."TP_STTS"<>'Manual NAK')
      16 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW' AND ("FTMREPORT"."TP_STTS"='Auto NAK' OR
                  "FTMREPORT"."TP_STTS"='Manual NAK' OR "FTMREPORT"."TP_STTS"='Validated'))
      19 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS CNCLO')
    Note: cpu costing is offCould you guys tell me what is wrong with this sql and how to tune it?
    Is there any way to replace the UNION? Is using UNION a good idea?
    Can I use DECODE or CASE WHEN to simplify it? How?
    Also, could you help explain why there is SYS_LE_4_0, SYS_TEMP_0FD9D660F_B198D56F temporary segment? Is it caused by with FTMReport as ?
    Thanks
    Edited by: PhoenixBai on Dec 31, 2009 9:58 AM
    Edited by: PhoenixBai on Dec 31, 2009 12:08 PM
    Edited by: PhoenixBai on Dec 31, 2009 12:17 PM

    I consider using GROUP BY ROLLUP together with DECODE, CASE WHEN, but haven`t come out with a working sql yet:-(Some sample data to work with would have been much helpful. But we dont get that most of the time :(
    I came up with this.
                    select case when ims_toms_msge_type = 'TOMS NEW' then
                                     case when grouping(tp_stts) = 1 then 'GRAND TOTAL'
                                          when tp_stts not in ('Validated','Auto NAK','Manual NAK') then 'Trades'
                                     end
                                when ims_toms_msge_type = 'TOMS CNCLO' then
                                     case when grouping(tp_stts) = 1 then 'CANCEL GRAND TOTAL'
                                          when tp_stts in ('Validated','Auto NAK','Manual NAK') then 'Cancel'
                                     end
                           end h1,
                           tp_stts,
                           count(*) count,
                           ims_toms_msge_type,
                           case when ims_toms_msge_type = 'TOMS NEW' then
                                     case when grouping(tp_stts) = 1 then 'H'
                                          when tp_stts not in ('Validated','Auto NAK','Manual NAK') then 'A'
                                     end
                                when ims_toms_msge_type = 'TOMS CNCLO' then
                                     case when grouping(tp_stts) = 1 then 'Z'
                                          when tp_stts in ('Validated','Auto NAK','Manual NAK') then 'B'
                                     end
                           end flag,
                           'MSL' FilterType
                   from ims_trde,
                        ims_toms_msge
                     where IMS_TRDE.PRCSG_GRP_ID  = 5 
                       AND IMS_TRDE.IMS_TRDE_RCPT_DTTM  >= TO_DATE('12/01/2009 00:00', 'MM/DD/YYYY HH24:MI')
                       AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <=  TO_DATE('12/28/2009 23:59', 'MM/DD/YYYY HH24:MI') 
                       AND (IMS_TRDE.GRS_TRX_TYPE NOT IN ('INJECTION','WITHDRAWAL','PAYMENT')
                        OR IMS_TRDE.GRS_TRX_TYPE IS NULL)
                       AND (IMS_TRDE.SSC_INVST_TYPE != 'FC'
                        OR IMS_TRDE.SSC_INVST_TYPE IS NULL)
                       AND (IMS_TRDE.SERVICE_TYPE = 'FS'
                        OR IMS_TRDE.SERVICE_TYPE = 'CO')
                       AND 1=1 
                     and IMS_TRDE.SERVICE_TYPE = 'FS'   
                     and  1=1 
                     and ims_trde.ims_trde_oid = ims_toms_msge.ims_trde_oid
                      group by rollup(ims_toms_msge_type, tp_stts)Not sure if this code works. Because i dint have the table or the data to test it. So if it has some error just fix it and give it a try. Do post the kind of output it gives. So that we can see if we can work with this solution.

  • Passing message from plsql code to page

    Hello Everybody,
    I am trying to pass a 'success message' from plsql code which runs on page processing to the page. This plsql is a insert statement and if statement runs successfully (on submit) then I want to show a success message on the page after summit.
    Your comment and help would be appreciated.
    Thanks,
    Raj.

    Thank you Tony.
    Stored Procedure which I am calling on the page is running in database. So if this procedure runs successfully(or vice versa), how I would know?? Is there a way to pass value from database stored procedure to it's calling page?
    Following is procedure:
    procedure load_stateday_result(key_loc ATM_STATE_DAY_INSP.KEY_LOCATION%type) is
    temp_key_insp ATM_INSPECTION.KEY_ATM_INSPECTION%type;
    temp_key_location number(8);
    temp_dte_schedule date;
    begin
    temp_key_location := key_loc;
    select key_atm_inspection,dte_schedule into temp_key_insp, temp_dte_schedule
    from atm_inspection where
    key_location = temp_key_location and exam_type = 'D' and exam_yr = to_char(sysdate,'yyyy');
    insert into atm_state_day_insp(key_atm_state_day_insp,key_location,key_atm_insp,scheduled_dte)
    values(state_day_insp_seq.nextval,key_loc,temp_key_insp,temp_dte_schedule);
    COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Error :'|| SQLCODE||':'||SQLERRM);
    --ROLLBACK;
    RAISE;
    end load_stateday_result;
    Will appreciate your reply.
    Thanks,
    Raj, NY

  • PLSQL code optimizing

    Hi
    My oracle db version is 11g R1/AIX5.3
    how following plsql code can be re-written for better performance
    CREATE OR REPLACE PROCEDURE CSCOMMON.POST_SEQ_PROCESS
    AS
       -- Declare variables to hold sequenced infomration.
       pragma autonomous_transaction;
       V_RECORD_ID           POST_SEQUENCING_PROCESS.RECORD_ID%TYPE;
       V_RECEIVED            POST_SEQUENCING_PROCESS.RECEIVED%TYPE;
       V_PROCESS_NAME        POST_SEQUENCING_PROCESS.PROCESS_NAME%TYPE;
       V_PROCESS_ID          POST_SEQUENCING_PROCESS.PROCESS_ID%TYPE;
       V_PROCESS_SEQ         POST_SEQUENCING_PROCESS.PROCESS_SEQ%TYPE;
       V_RECEIVER            POST_SEQUENCING_PROCESS.RECEIVER%TYPE;
       V_RECEIVER_ID         POST_SEQUENCING_PROCESS.RECEIVER_ID%TYPE;
       V_RECEIVER_SEQ        POST_SEQUENCING_PROCESS.RECEIVER_SEQ%TYPE;
       V_SENDER              POST_SEQUENCING_PROCESS.SENDER%TYPE;
       V_SENDER_ID           POST_SEQUENCING_PROCESS.SENDER_ID%TYPE;
       V_MESSAGE_ID          POST_SEQUENCING_PROCESS.MESSAGE_ID%TYPE;
       V_INSTANCE_ID         POST_SEQUENCING_PROCESS.INSTANCE_ID%TYPE;
       V_STATUS              POST_SEQUENCING_PROCESS.STATUS%TYPE;
       V_STEP_ID             POST_SEQUENCING_PROCESS.STEP_ID%TYPE;
       V_INTERNAL_ID         POST_SEQUENCING_PROCESS.INTERNAL_ID%TYPE;
       V_LOCK_ID             POST_SEQUENCING_PROCESS.LOCK_ID%TYPE;
       V_ERROR_HANDLING      POST_SEQUENCING_PROCESS.ERROR_HANDLING%TYPE;
       V_STARTED             POST_SEQUENCING_PROCESS.STARTED%TYPE;
       V_WARNINGS            POST_SEQUENCING_PROCESS.WARNINGS%TYPE;
       V_DOCUMENTTYPE_NAME   POST_SEQUENCING_PROCESS.DOCUMENTTYPE_NAME%TYPE;
       V_DOCUMENTTYPE_ID     POST_SEQUENCING_PROCESS.DOCUMENTTYPE_ID%TYPE;
       V_DOCUMENTTYPE_SEQ    POST_SEQUENCING_PROCESS.DOCUMENTTYPE_SEQ%TYPE;
       v_current             VARCHAR2 (600);
       v_sql_error           VARCHAR2 (600);
       lv_count              NUMBER;
       CURSOR c_first500
       IS
          SELECT RECORD_ID,
                 RECEIVED,
                 PROCESS_NAME,
                 PROCESS_ID,
                 PROCESS_SEQ,
                 RECEIVER,
                 RECEIVER_ID,
                 RECEIVER_SEQ,
                 SENDER,
                 SENDER_ID,
                 MESSAGE_ID,
                 INSTANCE_ID,
                 STATUS,
                 STEP_ID,
                 INTERNAL_ID,
                 LOCK_ID,
                 ERROR_HANDLING,
                 STARTED,
                 WARNINGS,
                 DOCUMENTTYPE_NAME,
                 DOCUMENTTYPE_ID,
                 DOCUMENTTYPE_SEQ
            FROM (  SELECT RECORD_ID,
                           RECEIVED,
                           PROCESS_NAME,
                           PROCESS_ID,
                           PROCESS_SEQ,
                           RECEIVER,
                           RECEIVER_ID,
                           RECEIVER_SEQ,
                           SENDER,
                           SENDER_ID,
                           MESSAGE_ID,
                           INSTANCE_ID,
                           STATUS,
                           STEP_ID,
                           INTERNAL_ID,
                           LOCK_ID,
                           ERROR_HANDLING,
                           STARTED,
                           WARNINGS,
                           DOCUMENTTYPE_NAME,
                           DOCUMENTTYPE_ID,
                           DOCUMENTTYPE_SEQ
                      FROM CSCOMMON.SEQUENCING_PROCESS
                  ORDER BY RECEIVED)
           WHERE ROWNUM < 101;
       P_RAND                NUMBER;
       V_LID                 NUMBER;
    BEGIN
       v_current := 'BEFORE CURSOR OPENING';
       SELECT COUNT (*) INTO lv_count FROM POST_SEQUENCING_PROCESS;
       OPEN c_first500;          
       LOOP
          SELECT CSCOMMON.SEQ_LID_SEQUENCING_PROCESS_NU.NEXTVAL
            INTO V_LID
            FROM DUAL;
         UPDATE CSCOMMON.SEQUENCING_PROCESS A
             SET A.LOCK_ID = V_LID ,
                 A.STATUS = 1,
                 A.STARTED = SYSDATE,
                 A.WARNINGS = 0
           WHERE NOT EXISTS
                        (SELECT 1
                           FROM CSCOMMON.SEQUENCING_PROCESS B
                          WHERE ( (A.RECEIVER_ID = B.RECEIVER_ID
                                   AND A.RECEIVER_SEQ = 1)
                                 OR (A.PROCESS_ID = B.PROCESS_ID
                                     AND A.PROCESS_SEQ = 1)
                                 OR (A.DOCUMENTTYPE_ID = B.DOCUMENTTYPE_ID
                                     AND A.DOCUMENTTYPE_SEQ = 1))
                                AND (A.ERROR_HANDLING = 0 OR B.STATUS != 4)
                                AND B.RECORD_ID < A.RECORD_ID)
                 AND A.STATUS = 2
                 AND 1024 =
                                        (SELECT WM1.STATUS
                           FROM WMLOG610.WMPROCESS WM1,
                                (  SELECT MAX (AUDITTIMESTAMP) AUDITTIMESTAMP,
                                          INSTANCEID
                                     FROM WMLOG610.WMPROCESS WM2
                                    WHERE INSTANCEID IN
                                             (SELECT INSTANCE_ID
                                                FROM CSCOMMON.SEQUENCING_PROCESS where rownum<101)
                                 GROUP BY INSTANCEID
                                 ORDER BY instanceid) WM2
                          WHERE     A.INSTANCE_ID = WM1.INSTANCEID
                                AND WM1.INSTANCEID = WM2.INSTANCEID
                                AND WM1.AUDITTIMESTAMP = WM2.AUDITTIMESTAMP
                                AND ROWNUM = 1)
                 AND A.LOCK_ID IS NULL
                 AND A.DOCUMENTTYPE_NAME != 'FxHaulage';
    commit;
          FETCH c_first500
          INTO V_RECORD_ID,
               V_RECEIVED,
               V_PROCESS_NAME,
               V_PROCESS_ID,
               V_PROCESS_SEQ,
               V_RECEIVER,
               V_RECEIVER_ID,
               V_RECEIVER_SEQ,
               V_SENDER,
               V_SENDER_ID,
               V_MESSAGE_ID,
               V_INSTANCE_ID,
               V_STATUS,
               V_STEP_ID,
               V_INTERNAL_ID,
               V_LOCK_ID,
               V_ERROR_HANDLING,
               V_STARTED,
               V_WARNINGS,
               V_DOCUMENTTYPE_NAME,
               V_DOCUMENTTYPE_ID,
               V_DOCUMENTTYPE_SEQ;
          EXIT WHEN c_first500%NOTFOUND;
          BEGIN
             v_current := 'INSERT INTO POST_SEQUENCING_PROCESS';
             IF (lv_count = 0)
             THEN
                INSERT INTO POST_SEQUENCING_PROCESS (RECORD_ID,
                                                     RECEIVED,
                                                     PROCESS_NAME,
                                                     PROCESS_ID,
                                                     PROCESS_SEQ,
                                                     RECEIVER,
                                                     RECEIVER_ID,
                                                     RECEIVER_SEQ,
                                                     SENDER,
                                                     SENDER_ID,
                                                     MESSAGE_ID,
                                                     INSTANCE_ID,
                                                     STATUS,
                                                     STEP_ID,
                                                     INTERNAL_ID,
                                                     LOCK_ID,
                                                     ERROR_HANDLING,
                                                     STARTED,
                                                     WARNINGS,
                                                     DOCUMENTTYPE_NAME,
                                                     DOCUMENTTYPE_ID,
                                                     DOCUMENTTYPE_SEQ)
                     SELECT *
                       FROM cscommon.sequencing_process A
                      WHERE lock_id IS NOT NULL
                            AND A.DOCUMENTTYPE_NAME != 'FxHaulage' order by lock_id;
                            commit;
                INSERT INTO CSCOMMON.PRE_SEQUENCING_PROCESS
                   (SELECT * FROM CSCOMMON.POST_SEQUENCING_PROCESS);
    commit;
                DELETE FROM CSCOMMON.POST_SEQUENCING_PROCESS;
                COMMIT;
                v_current := 'DELETE FROM SEQUENCING_PROCESS';
                DELETE FROM CSCOMMON.SEQUENCING_PROCESS
                      WHERE LOCK_ID IS NOT NULL
                            AND DOCUMENTTYPE_NAME != 'FxHaulage';
                COMMIT;
             ELSE
                RETURN;
             END IF;
          END;
       END LOOP;
       CLOSE c_first500;                    
       COMMIT;
    EXCEPTION
       WHEN OTHERS
       THEN
          v_sql_error := SQLERRM || ' - ' || v_current;
          ROLLBACK;
    END;
    /May be by using forall /bulk collections
    Thanks
    Raj

    You need to understand transactional consistency. Not only are your commits
    slowing things down, they are not good for maintaining transactional consistency.
    Ask yourself what would happen if there was a problem in your procedure after
    the first commit? How would you recover from that with some records
    updated but the rest of your procedure not having been run?
    In general you should only have one commit at the topmost level. By that I mean if
    there is a program that kicks of other ones and is the 'master' controller, that
    should be the one that decides to commit or rollback the whole transaction.
    Also you need to understand exception handling. Your exception processing is dangeroulsly wrong.
    Remove it.
    Finally, try and do this processing without using cursor loops: pure (set-based) SQL is much faster than
    slow cursor based PL/SQL and SQL together.

  • Plsql code to insert data in table

    HI
    I want to write a procedure in such a way that
    If IMDMMANUFACTURER_VM table exit
    then
    insert into IMDMMANUFACTURER_dummy table from IMDMMANUFACTURER_VM
    else
    insert into IMDMMANUFACTURER_dummy table from IMDMMANUFACTURER table
    how I write the code in plsql?
    Thanks in adv

    Hi Blu
    i accept there is a declaration error there.. but Blu.. it had worked for me... then one
    doubt , why we have to use Dynamic SQL for a DML statement even after knowing all the parameters of the
    statement.
    Pl correct me if my perspective is wrong
    SQL*Plus: Release 9.0.1.0.1 - Production on Mon Sep 15 20:06:10 2008
    (c) Copyright 2001 Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
    With the Partitioning option
    JServer Release 9.0.1.1.1 - Production
    SQL> select table_name
      2  from all_tables
      3  where table_name like 'emp_aasi%';
    no rows selected
    SQL> desc test1;
    Name                                      Null?    Type
    A                                                  VARCHAR2(4)
    B                                                  NUMBER(2)
    SQL> select * from test1;
    no rows selected
    SQL> DECLARE
      2  v_count NUMBER;
      3  BEGIN
      4  v_count :=0;
      5 
      6  SELECT COUNT(1) INTO v_count
      7  FROM All_Tables
      8  WHERE table_name='emp_aasign';
      9 
    10  IF v_count > 1 THEN
    11  INSERT INTO test1 ( SELECT '1', '2' FROM dual);
    12  ELSE
    13  INSERT INTO test1 ( SELECT '3', '4' FROM dual);
    14  END IF;
    15  END;
    16  /
    PL/SQL procedure successfully completed.
    SQL> select * from test1;
    A             B
    3             4
    SQL>

  • Global Value in PLSQL Code

    How to take value of Total Compenations- >Basic -> Global Value in PLSQL Code.
    Thanks

    The Global values are stored in the table FF_GLOBALS_F, write a cursor in plsql to get the value from this table.
    Regards,
    Senthil

Maybe you are looking for