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.

Similar Messages

  • ORA-01403: no data found Error in PLSQL code raised during plug-in processing.

    Hello OTN community,
    We are having the access to APEX problem. a New user was setup to access the APEX application. When I test to login as a new user, I get the message "ORA-01403: no data found Error in PLSQL code raised during plug-in processing.". When click OK to the disply message, the application will take me out of the sstem. I need help to even understand what is happening. I didn't develop the application, there is no documentation for this application, I am just supporting the application whenever there is a problem and I am new to APEX. As you can see I need help to figure this thing out. Your help is dearly appreciated.
    Thank you OTN

    Try to check the query that is executed and check if there is data or not

  • 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

  • Displaying Images in a Report or in PLSQL Code

    Hi all,
    I have a products catelog in an items table (item_id, item_name, item_image (blob)). I want to display it in a table form but Reports in Portal30 do not allow images.
    I can write simple PLSQL code to display table contents in tabular form (using htp, htp packages) but I could not find any procedure/function to display image stored in a db table to an HTML table.
    I shall be grateful for any help or hint regarding this. You can mail me directly if you like.

    Armaghan
    This question is best asked in the Oracle9iAS Portal Applications Forum.

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

  • URGENT HELP: When some users submit, application carries empty fields from html components to plsql code

    Hi APEX users and developer, especially forum's active users, please get me rid of this problem because it is really very bad situation.
    I have a real trouble with application. It behaves unusual. Application is used by 60 users but only 3 of them have these problem and they can not use the application anymore.
    Application is
    http://apex.oracle.com/pls/apex/f?p=70547
    After fields are filled and some rows checked from tabular form in page, user submits the page. Process called newReyestr calls plsql procedure from package with inputs from page. But only same 3 users get empty fields in plsql code. I see it just after when the first line stepped in procedure.
    So, "what is the problem?"

    Hi NoGot,
    you know, I have not written big quote. The code was big. But it has no any meaning. Because problem is in first line. No need to understand it.
    There is no any difference between those users. They also tried it from different browser and even computers.
    BTW: I am not russian.

  • NLS issue in Java/PLSQL code [ using ROWID]

    I have NLS related question regarding the following scenario in Java/PLSQL code ::-
    OracleResultSet ors = (OracleResultSet) stmt.executeQuery("select rowId from t where t.col = 'XX'");
    // The above query could return multiple rowIds.
    String strVal1 = null;
    String strVal2 = null;
    if(ors.next())
    strVal1 = ors.getROWID(1).stringValue();
    if(ors.next())
    strVal2 = ors.getROWID(1).stringValue();
    ArrayList strList = new ArrayList();
    strList.add(strVal1);
    strList.add(strVal2);
    Now I need to pass a list of rowId's from Java to PLSQL function f().
    oracle.sql.ARRAY rowListArr = convertArrayListToRowPointerList(strList, conn) ;
    OracleCallableStatement cstmt = (OracleCallableStatement)
    cstmt.prepareCall("begin f(?); end;");
    cstmt.setObject(1, rowListArr);
    cstmt.execute();
    where:-
    static oracle.sql.ARRAY convertArrayListToRowPointerList(ArrayList arr, Connection conn)
    throws SQLException {
    oracle.sql.ArrayDescriptor stDesc = ArrayDescriptor.createDescriptor
    ("DBUSER.ROWPOINTERLIST", conn);
    oracle.sql.Datum[] keyVals= new oracle.sql.Datum[arr.size()];
    for(int i = 0; i < arr.size(); i++) {
    keyVals[i] = new oracle.sql.CHAR((String) arr.get(i),
    oracle.sql.CHAR.DEFAULT_CHARSET);
    oracle.sql.ARRAY keyArr = new oracle.sql.ARRAY(stDesc, conn, keyVals);
    return keyArr;
    and
    create or replace type DBUSER.ROWPOINTERLIST as table of varchar2(4000);
    Will there be NLS issues in the above code, where I pass the rowId content
    that I obtain from one query, as array of string bind variables to a subsequent PLSQL procedure? --- first approach
    Or
    do I need to pass the rowId list , as a array of oracle.sql.ROWID via bind variables? -- second approach
    The problem I have in second approach is that in the DB we cannot define a type as a table of ROWID's. So currently I have RowPointerList as a table of varchar2's (note the length of list of rowId is not predetermined in my case, so I user table instead of varray).
    However I was wondering if the first approach will have any NLS issues.
    Will appreciate your comments.
    Thanks

    ROWIDs are represented as either hex-encoded values or base64 encoded values. Both encodings use pure ASCII, so there should be no NLS issues.
    I am not very familiar with the oracle.sql.ARRAY type, but unless absolutely necessary, I would avoid the oracle.sql.CHAR datatype (assuming 10g drivers). Using java.lang.String is preferred.
    -- Sergiusz

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

  • Can i submit  a page and later execute a plsql code in some seperate page..

    I have a page.. this page has a button and the action for it is submit ..database action is insert activity..What i need is the moment
    i press the button .. after the submit activity has been done .. a plsql procedure which fires when i redirect to page.. 100 also be executed.
    Normally if my button action type is redirect to page .. Then this procedure gets executed...Since it is in redirected page.
    But If I change the action type... to submit this is not possible . ..Since the activity that occurs is the database insert activity..
    I also need the plsql code which is other page to be executed..
    Any information provided will be appreciated.

    i got it solved.. issue was..just
    needed to write a plsql code.. which will do a insert activity and then ..it does a redirect of page..I changed the button action from submit to link to page
    Issue is sorted
    Thanks

  • 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

  • Which are the advantages of OWB Mappings over PLSQL code?

    Hi,
    I was wondering which are the advantages of OWB (10gr2 or 11g) Mappings vs simple PLSQL code when the mappings are, for performance reasons, only generated in set based mode.
    Regards
    Maurice

    I'd say it's the general benefits that an ETL tool is considered to have over hand crafted code e.g. maintainability and traceability. The latest versions of OWB also make it even easier to maintain TYPE2 dimensions etc.
    Of course benefits go the other way as well in that if you want the optimum performing code then a skilled PL/SQL developer will deliver that.
    Cheers
    Si

  • 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 for button.....

    i have a page which contain fields term_id,*term_desc*,*term_condition*
    and some buttons Add,*delete* and save..
    Actually no data in the table..
    when i press Add button the term_id should get increment by '1' .
    where i have to wite the below coding in Edit Add button?
    can i put the coding in Conditional Item Display condition type PLSQL?
    declare
    a number;
    begin
    select max(nvl(term_id,0))+1 into a from term_creation;
    *:P5_TERM_ID*:=a;
    end;
    Edited by: skud on Mar 5, 2011 2:05 AM

    You can submit the page with a request say "MY_REQUEST" and run a conditional PLSQL block(request equal to MY_REQUEST) and add the PLSQL code there.
    If you want to do it without submitting page
    <li>Apex Version 4 : Add an id to button (button attributes, id ="MY_BUTTON" ) and add a Dynamic Action fired on click of DOM element : MY_BUTTON , event type would be PLSQL and write your PLSQL code there(add required page items to be submitted in the field)
    <li>Apex 3.x and 2.x(works iwth apex 4 too), create an ondemand PLSQL process, call the process from a javascript function(add the item values to session using the ajax request handle) and call the javascript function from the button click( action type: redircet to URL , javascript:function_name(parameter1,parameter2) )

  • PLSQL code in a javascript code

    Can i write the PLSQL code in a javascript code?
    Actually i want to pass a value into a PLSQL code. First in javascript code i have to read a value of page item :PX_ITEM, then i have to pass that value in PLSQL code.

    Can i write the PLSQL code in a javascript code?No.
    PL/SQL runs in the database on the server. JavaScript runs in the browser on the client. Never the twain shall meet.
    Passing values between them requires a page submit or AJAX call.

  • 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

Maybe you are looking for