Multithreading in  oracle PLSQL

Hi
I am having 100000 records in my database,
Normally i fetch 1000 records from 100000 in bulk and do the process, after completion of first batch the it took second set of 1000 records from 100000 in bulk and do the process.
Say in the 1st batch there is a transaction for the A/C no : 9856423456
after completion of batch 1
2nd batch is in process here some transaction for the same A/c : 9856423456
so complete this batch
and batch process is continuous till completion of whole record.
there is a dependences between 1st batch and 2nd or some other batch
say in the 1st batch transaction for the A/C no : 9856423456 after completion of this transaction balance available for the A/C no : 9856423456 2,00,000 rupees
in the 2nd or some other batch, some transaction may come for same A/c, so after completion of the first batch only we know what actual balance is.
Now i want implement multi-threading :
how can i implement
Thanks

Balajiraam wrote:
Now i want implement multi-threading : how can i implementThere 2 basic options to parallel processing using PL/SQL.
You can use the Parallel Query (PQ) feature of Oracle. This parallelises SQLs by breaking large scans into a number of smaller scans and running these in parallel. You can also run PL/SQL via PQ by defining a parallel enabled PL/SQL pipeline table function.
This second method is rolling your own parallel processing in PL/SQL. With 11g you can use DBMS_PARALLEL_EXECUTE. You can use DBMS_JOB to run parallel processes. You can use message queues and database pipes (or even plain SQL tables) for IPC. You can use DBMS_LOCK for implementing semaphores and mutexes.
It all depends on your requirements ito multi-threading/parallel processing in PL/SQL.

Similar Messages

  • How to do Multithreading in Oracle PlSql using a Single Session

    Hi All,
    I have a complex but interesting requirement.
    1) I have a table with 90k rows.
    2) My PlSql Package picks up all the 90k rows one by one, does some processing/transformation on it
    3) if the row satisfies some business rules, then it gets inserted into an application table. If the row is not eligible, then it inserts the row into a Error table.
    4) After processing all the 90k records, If my Error Table Count reaches 10% of the input count (90k), then all inserts (i.e. both application table inserts and
    error table inserts) must be rolled back.
    5) Right now, we are achieving this logic in a single session but there are far many performance issues, because processing has to go through row by row.
    Is it possible to implement the above logic as "multi threading within PlSql" whereby i can run Step 2 in 10 parallel slaves and if the total error count of all the 10 slaves exceeds 10% of the input data, then there should be a rollback for all 10 slaves.
    +A sample testcase is given below. Issue is: rollback statement in p1 is not taking any effect (because plsql spawns sessions to execute p2 which autocommits itself on graceful exit). But is there any other way by which i can make the rollback to be effective+
    create table t1 (a number);
    create table j1(b number);
    create or replace procedure p1
    as
    l_cnt number;
    i number;
    l_job number;
    begin
         for i in 1 .. 5 loop
            dbms_job.submit( l_job, 'p2('||i||');' );       
        end loop;
        commit;
        loop
            dbms_lock.sleep(30);
            select count(*) into l_cnt from j1;
            exit when (l_cnt = 5);
        end loop;
       rollback;
    end;
    create or replace procedure p2(i number)
    as
    begin
    insert into t1 values(i);
    insert into j1 values(1);
    end;
    /

    Basically your current 'algorithm' can be described as 'slow-by-slow processing' (co Tom Kyte)
    Relational databases are about sets not about records.
    Consequently your approach must be qualified as evil.
    Instead of fixing the problem (and getting rid of slow-by-slow processing), you propose to add even more evil by adding multi-threading to the mix.
    The issue you describe is not an issue at all, it is just making clear you are heading for disaster.
    An approach that works quite nicely is
    - add an extra status column to the table to be processed.
    - UPDATE the status column of all records that do not qualify. By UPDATE I mean the UPDATE statement, not record by record processing
    - (BULK)-INSERT the remaining records, for which the flag is NULL.
    The simple guidelines for application development are:
    Only do it in PL/SQL when you can't do it in straight SQL
    Only do it in Java when you can't do it in PL/SQL
    Only do it in 3GL when you can't do it in Java.
    Your 'strategy' is doomed to fail.
    Get rid of it.
    Before it is too late, and your heart is pumping like mad, because your problems are increasing, and increasing, and increasing, and you have to work 7 x 24 to deal with 'performance problems'
    You have already demonstrated your approach doesn't work.
    Don't try to make it worse.
    Sybrand Bakker
    Senior Oracle DBA
    Experts: those who do read documentation

  • 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 process next record in oracle PLSQL

    Hi,
    I am processing below record set with the help of BULK COLLECT in Oracle PLSQL Procedure. While processing I am checking model is one that need not be substituted. If it is 'NA' or 'N/A', I need process next record (marked as bold in code snipet)
    Please guide me how to do it ?
    TYPE t_get_money IS TABLE OF c_get_money%ROWTYPE INDEX BY BINARY_INTEGER;
    L_money t_get_money ;
    L_subst_model VARCHAR2(40);
    L_Notify_Manager     VARCHAR2(1);
    L_grade          VARCHAR2(20);
    L_Error_Message     VARCHAR2(1);
    BEGIN
    OPEN c_get_money ;
    FETCH c_get_money BULK COLLECT INTO L_money ;
    CLOSE c_get_money;
    FOR I IN 1..L_money.count LOOP
    -- check if the model is one that need not be substituted
    IF (upper(L_money(i). subst_model) in ('N/A', 'NA')
    THEN
    L_NOTIFY_MANAGER(I) := 'Y';
    L_GRADE(I) := 'ERROR';
    L_error_message(i) := 'substitute Model is not N/A or NA' ;
    -------Here I want to process NEXT RECORD--------
    END IF ;
    END;

    One of the solution for below version of 11g...
    DECLARE
         TYPE t_get_money IS TABLE OF c_get_money%ROWTYPE
                                       INDEX BY BINARY_INTEGER;
         L_money              t_get_money;
         L_subst_model        VARCHAR2 (40);
         L_Notify_Manager   VARCHAR2 (1);
         L_grade              VARCHAR2 (20);
         L_Error_Message    VARCHAR2 (1);
    BEGIN
         OPEN c_get_money;
         FETCH c_get_money
         BULK COLLECT INTO L_money;
         CLOSE c_get_money;
         FOR I IN 1 .. L_money.COUNT LOOP
              IF UPPER (L_money (i).subst_model) IN ('N/A', 'NA') THEN
                   GOTO Nextrecord;
              END IF;
              L_NOTIFY_MANAGER (I)   := 'Y';
              L_GRADE (I)              := 'ERROR';
              L_error_message (i)    := 'substitute Model is not N/A or NA';
            <<Nextrecord>>
              NULL;
         END LOOP;
    END;One of the solution for 11gR1 and above...
    DECLARE
         TYPE t_get_money IS TABLE OF c_get_money%ROWTYPE
                                       INDEX BY BINARY_INTEGER;
         L_money              t_get_money;
         L_subst_model        VARCHAR2 (40);
         L_Notify_Manager   VARCHAR2 (1);
         L_grade              VARCHAR2 (20);
         L_Error_Message    VARCHAR2 (1);
    BEGIN
         OPEN c_get_money;
         FETCH c_get_money
         BULK COLLECT INTO L_money;
         CLOSE c_get_money;
         FOR I IN 1 .. L_money.COUNT LOOP
              IF UPPER (L_money (i).subst_model) IN ('N/A', 'NA') THEN
                   CONTINUE;
              END IF;
              L_NOTIFY_MANAGER (I)   := 'Y';
              L_GRADE (I)              := 'ERROR';
              L_error_message (i)    := 'substitute Model is not N/A or NA';
         END LOOP;
    END;

  • Write to word document from oracle plsql

    Hi,
    Please provide methods to create and write to a word document from ORACLE PLSQL.We tried using UTL FILE package but it writes as ascii text.

    Divs wrote:
    The server m/c operating system is unix.so we need to invoke the procedure from Unix Os.In that case - not possible. For Windows COM (Component Object Model) to work, Oracle database need to be able to call and load the COM dynamic link libraries.
    Not to say that it is not possible. Have never used DCOM (the Distributed COM interface), and not exactly sure what it requires. Assuming that DCOM is not usable from a Linux perspective, you can still provide a manual interface. You create a NT tcp/ip service that exposes the COM interface calls that you need - in a secure fashion (even better - you can provide a higher level abstraction layer for the COM interface that does the specific job you need to be done).
    From Oracle you can then use PL/SQL's UTL_TCP package to open a connection to it and via this service craft a Word document on that Windows server.
    Are there web services for MS Office? I know Google is pushing that aspect hard (and embroiled in lawsuits with the US government and Microsoft about tender awards in this aspect). Now if Microsoft has "+office-on-the-web+", then one can create a Word document via a web browser. This means that there is an underlying web service - and that this can be called and used. The Evolution (Open Source Mail Reader) project for example uses the MS Exchange web service interface to provide a seamless interface to Exchange mail accounts (have used this everyday for a number of years now).
    The real question I would however ask is why Word specifically? Why not a more common format like PDF? You can even consider generating XML instead. Both Microsoft and Open Office and others are supporting XML formatted word processing documents (as oppose to older proprietary and binary formats).
    And why not use a Report Writer? I'm a big fan of doing as much as possible in Oracle (using PL/SQL most of the time). But certain things, like generating Word-style documents would be better done (and more flexible too) using a Report Writer.

  • Oracle/PLSQL: ORA-00932 ErrorError: ORA-00932: inconsistent datatypes

    I am getting this error in a PL/SQL package, using SQL using the NVL function.
    Oracle/PLSQL: ORA-00932 ErrorError: ORA-00932: inconsistent datatypes. Cause: You tried to perform an operation between two different datatypes, but the datatypes are not compatible.
    I do not get this error on a 10.2.0.4 instance of the database running in Windows.
    Anyone come accross this type of issue in 11g Rel.2 or after migrating from 10g to 11g??
    Thanks.

    Dear user520935,
    What are the contents of the package? Where do you exactly get that error?
    http://ora-00932.ora-code.com/
    Have you checked the metalink about it? There are lots of articles about it.
    Ogan

  • What are collections in oracle plsql, and Transpose concepts.

    Hi OTN,
    what are the collections available in Oracle Plsql, what are concepts of collection.
    How to Transpose a Table from rows to columns or columns into rows.
    DDL and DML concepts.
    What is the concepts of statistics in Oracle Plsql.
    Thanks
    Edited by: 945059 on Aug 22, 2012 4:52 AM

    945059 wrote:
    Hi OTN,
    what are the collections available in Oracle Plsql, what are concepts of collection.
    How to Transpose a Table from rows to columns or columns into rows.
    DDL and DML concepts.
    What is the concepts of statistics in Oracle Plsql.
    Thanks
    Edited by: 945059 on Aug 22, 2012 4:52 AMhttp://www.google.co.in/search?hl=en-IN&source=hp&q=collections+oracle&gbv=2&oq=collections+oracle&gs_l=heirloom-hp.3..0l4j0i30l6.2031.5874.0.6561.18.17.0.0.0.0.422.3217.2-4j4j2.10.0...0.0...1c.l6qRfaAtkWM&safe=active
    SQL and PL/SQL FAQ
    http://www.google.co.in/search?q=performance+tuning+oracle&hl=en-IN&gbv=2&gs_l=heirloom-hp.3..0l4j0i30l6.2031.5874.0.6561.18.17.0.0.0.0.422.3217.2-4j4j2.10.0...0.0...1c.l6qRfaAtkWM&safe=active&oq=performance+tuning+oracle

  • Oracle PLSQL Send mail Issue.

    Hi All,
    I used to send some emails using oracle PLSQL code in both 10 g and 11g.But now days mail is getting triggered without any body in both the 10g and 11g versions.
    Some mails are triggering perfectly.I am unable to sort out the issue, please help me in this concern.

    Code that i have used is:
    create or replace
    PROCEDURE Sendmail(V_MAILHOST VARCHAR2,V_FROM VARCHAR2,V_TO clob ,V_CC VARCHAR2, V_SUBJECT VARCHAR2,V_MSGTEXT VARCHAR2,V_MODULE VARCHAR2) AS
      l_mail_conn   UTL_SMTP.connection;
      l_subject      VARCHAR2(100):='test mail';
      l_msg_text   VARCHAR2(500):='hi , testing alert mail';
      v_reply      utl_smtp.reply;
      L_RECIPIENTS  clob;
      l_recipients1  clob;
      V_TO1            clob;
      v_errmsg        VARCHAR2(500);
      mul_recip        NUMBER;
      mul_recip1        NUMBER;
      slen             NUMBER:=1;
      slen1             NUMBER:=1;
      V_errcode        VARCHAR2(500);
    BEGIN
      l_mail_conn:= UTL_SMTP.open_connection(v_mailhost,25);
       v_reply :=UTL_SMTP.helo(l_mail_conn, v_mailhost);
       v_reply :=UTL_SMTP.mail(l_mail_conn, v_from);
      -- V_TO1:=null;--'[email protected]';
       SELECT INSTR(V_TO,',') INTO mul_recip FROM dual;
        IF mul_recip =0
        THEN
             utl_smtp.rcpt(l_mail_conn, V_TO );
        ELSE
            WHILE(INSTR(V_TO,',',slen) > 0)
            LOOP
                  l_recipients := SUBSTR(V_TO, slen, INSTR(SUBSTR(V_TO,slen),',')-1);
                  slen := slen+INSTR(SUBSTR(V_TO, slen),',');
                utl_smtp.rcpt(l_mail_conn, l_recipients);
            END LOOP;
                l_recipients := SUBSTR(V_TO, slen);
                utl_smtp.rcpt(l_mail_conn, l_recipients);
        END IF;    
         IF V_CC IS NOT NULL
         THEN
          SELECT INSTR(V_CC,',') INTO mul_recip1 FROM dual;
        IF mul_recip1 =0
        THEN
             utl_smtp.rcpt(l_mail_conn, V_CC );
        ELSE
            WHILE(INSTR(V_CC,',',slen1) > 0)
            LOOP
                  l_recipients1 := SUBSTR(V_CC, slen1, INSTR(SUBSTR(V_CC,slen1),',')-1);
                  slen1 := slen1+INSTR(SUBSTR(V_CC, slen1),',');
                utl_smtp.rcpt(l_mail_conn, l_recipients1);
            END LOOP;
                l_recipients1 := SUBSTR(V_CC, slen1);
                utl_smtp.rcpt(l_mail_conn, l_recipients1);
        END IF;    
    END IF;        
    v_reply :=utl_smtp.open_data(l_mail_conn );
    utl_smtp.write_data(l_mail_conn, 'From: ' || V_FROM || utl_tcp.crlf);
    utl_smtp.write_data(l_mail_conn, 'Subject: ' || v_subject || utl_tcp.crlf);
    utl_smtp.write_data(l_mail_conn, 'To: ' || V_TO || utl_tcp.crlf);
    utl_smtp.write_data(l_mail_conn, 'CC: ' || V_CC || utl_tcp.crlf);
    utl_smtp.write_data(l_mail_conn, 'Content-Type: text/html' || utl_tcp.crlf);
    UTL_SMTP.WRITE_DATA(L_MAIL_CONN, V_MSGTEXT );
      if length(V_TO)>=4000 then
      dbms_output.put_line('none');
      else
       insert into MAIL_LOG(MAILFROM, MAILTO, SUBJECT, LOGGED_DATE, MAIL_STATUS, MAILCC, MAILTEXT,MODULE_ID)
          VALUES(V_FROM,v_to,V_SUBJECT,SYSDATE,'sent',V_CC,V_MSGTEXT,V_MODULE);
        end if;
        utl_smtp.close_data(l_mail_conn );
        utl_smtp.quit(l_mail_conn);
    EXCEPTION
    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
        BEGIN
          UTL_SMTP.QUIT(l_mail_conn);
        EXCEPTION
          WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
            NULL; -- When the SMTP server is down or unavailable, we don't have
                  -- a connection to the server. The QUIT call will raise an
                  -- exception that we can ignore.
        END;
         v_errmsg:='Failed to send mail due to the following error: ' ||SQLERRM||' errcode '||SQLCODE||'from :'||V_FROM|| ' V_TO '||V_TO;
    INSERT INTO MAIL_LOG(MAILFROM, MAILTO, SUBJECT, LOGGED_DATE, MAIL_STATUS, MAILCC, MAILTEXT,MODULE_ID)
    VALUES(V_FROM,v_to,V_SUBJECT,SYSDATE,v_errmsg,V_CC,V_MSGTEXT,V_MODULE);
    END Sendmail;

  • Need help in understanding oracle plsql design phase.

    I am new user learning oracle plsql. I wanted to know following points.
    1) Is there any process we follow before developing oracle procedures.
    2) Is there any algorithm, flowchart, diagrams we use for orcale procedure development.
    3) What should I learn in order to start developing oracle procedures.
    flow charts
    data flow diagrams
    In there any standard used in industry ? any pointers/comments would be helpful

    1) It is different in every shop and even within a shop with different developers. The best thing for someone learning is to read the books and blogs of Tom Kyte and Steven Feuerstein and choose one. Though I must confess now that I have become a fan of Bryn Lewellyn's White Papers I may never go back.
    Try one out yourself:
    http://www.oracle.com/technology/tech/pl_sql/pdf/doing_sql_from_plsql.pdf
    PS: No one knows PL/SQL better than Bryn.
    2) No. Every procedure is different. What one writes to solve one business problem may bear no relationship to what one writes to solve another. My caveats would be:
    A. SQL before PL/SQL
    B. Arrays before single row processing (that means FORALL and BULK COLLECT)
    C. Don't write line 1 without reading Tom Kyte's observations about bind variables
    3) In this order:
    A. anonymous blocks
    B. how to declare constants
    C. how to declare variables
    D. how to create control structures
    E. exception handling
    F. bulk collect and forall statements
    G. DBMS_SQL built-in package
    H. Native dynamic SQL
    You will find demos of all of the above here:
    www.morganslibrary.org/library.html

  • Need help in regarding Oracle PLSQL developer interview questions

    Hi all,
    I am totally new in this field regarding plsql. I have just finished training in oracle plsql and in oracle financials. But for starting career i am looking jobs as:Oracle plsql developer. Can somebody help me what type of questions people going to ask? I am not confident yet, i have made my resume but for submitting resume i just want to be aware for the interview questions. Can somebody help me in telling me good questions and answers as to what to prepare?
    Thanks in advance.

    1.
    Do you have experience in Oracle 10g? If so, what are your favorite new features? (shows depth of experience and how well they are keeping up with technology)
    2.
    Partitioning (Practical Scenarios)
    1.
    Have you ever worked with partitioned tables? Example:
    2.
    What types of partitioning?
    3.
    What types of indexing, global or local? Why did you choose global or local?
    4.
    What do you see in SQL that is accessing partitioned tables that enables Oracle to take advantage of partitioning?
    5.
    What is partition pruning?
    3.
    PL/SQL Bulk Features
    1.
    Have you ever used PL/SQL bulk features? Which ones? Can you provide an example?
    2.
    What makes bulk processing faster?
    3.
    What PL/SQL data constructs are required to use bulk features?
    4.
    Oracle Collections
    1.
    What are the three types of collections?
    2.
    When would you use a varray versus a nested table?
    5.
    Global Temporary Tables
    1.
    Have you ever used Global Temporary Tables? Example:
    2.
    How does Oracle treat Global Temporary Tables differently than regular tables, making them faster?
    6.
    Autonomous Transactions
    1.
    What is an autonomous transaction? Example:
    7.
    SQL Tuning
    1.
    Someone comes to you with a SQL statement that is running slow, what are some potential problems that can be identified just by looking at the SQL statement?
    2.
    What are the steps you follow in the database to tune SQL?
    8.
    Locking Techniques
    1.
    Types of Locks
    1.
    Optimistic
    2.
    Pessimistic
    3.
    Lock Escalation
    9.
    Autonomous transactions, where to use examples if any
    10.
    Difference between Truncate and Delete Statement
    11.
    PL/SQL tables, index by tables, VARRAY, associate arrays, differences and when to use
    12.
    Performance tuning related, Using Explain plan, SQL* Plus auto trace, and using tkprof
    13.
    Different types of joins oracle uses ( Hash join, Merge Join, Nested loop join)
    14.
    Oracle SQL ANSI syntax ( JOIN USING, JOIN ON, LEFT OUTER JOIN,RIGHT OUTER JOIN etc..)
    15.
    dbms_profiler package uses
    16.
    Unit testing approach, if you know and worked on out PLSQL frame work for automatic testing, its big advantageous
    17.
    Oracle approach for read consistency, what is SCN, dirty reads, phantom reads etc..
    18.
    Standards ( Coding standards, naming standards etc.) , There are guidelines and naming standards for variables, package, procedure, function names, database object names etc…( Be prepared what standards you followed in previous projects )
    19.
    Snapshot too old error, fetch out of sequence error when it comes, should be able to explain.
    20.
    Oracle block, what it contains. Row chaining, row migration concepts
    21.
    Version control software’s (experience in clearcase and clearquest is big advantage). If you have not used these, know about the importance of these and be prepared to explain which ones you used in previous projects, and how the PL/SQL code used to deploy.
    22.
    Oracle server architecture, know about oracle memory structures, background processes overview

  • Oracle plsql with unix example

    Hi frd
    i working oracle plsql and Unix individually but how to work together in plsql with unix , kindly give me example any material send me

    959406 wrote:
    thank for reply
    oracle table how to view using shell scripting
    shell scripting access oracle table
    sqlplus
    the shell knows nothing about oracle.
    What real problem are you trying to solve?  No, view a table using shell scripting is not a problem to be solved, it is a technique, and probably not the best technique for your unknown problem.

  • Multithreading in Oracle

    Hi All,
    I am working on Oracle 11g. I have to implement multithreading/asynchronous processing in one of my applications.
    There is a table, tab1 which contains two columns - ID and SQL. The SQL column is of CLOB datatype and contains a Dynamic SQL statement. This table has around 100 records and can contain upto 1000 (not more than that). The intent of these Dynamic SQLs is to update one of the tables and the dynamic sql is quite big (creates temp tables, business logic application, data is merged and finally updates are done, again based on rules). As of now, the application was executing these queries in sequential manner, through a simple loop.
    I want to explore how can I introduce multithreading here, so that I can run the sqls in multiple threads. I know, I can use DBMS_SCHEDULER, but I am struggling at - how to break those 100 records into say 10 sessions at a time? I can track the IDs which have been processed by updating an update_date column in the above mentioned table.
    Any suggestion will be highly appreciated which can put me in right direction.
    If the problem statement is not clear, do let me know.

    Hi,
    I have never used before DBMS_SCHEDULER but the system parameter job_queue_processes should define the maximum number of jobs running at the same time. If set to 0 Oracle will determine it.
    I have prepared a sample dummy code that is creating 50 jobs and starting them.
    The parameter job_queue_processes is set to 10.
    From the log table mylog you will see only 10 jobs are executing at the same time.
    -- Table to store my SQL jobs
    CREATE TABLE myjobs
       id             NUMBER NOT NULL
    , SQLCODE        CLOB
    -- Table to store log of my jobs
    CREATE TABLE mylog
       start_time     TIMESTAMP NOT NULL
    , end_time       TIMESTAMP NOT NULL
    , id             NUMBER NOT NULL
    -- Creating entries into myjobs table
    BEGIN
       FOR i IN 1 .. 50
       LOOP
          INSERT INTO myjobs
               VALUES (
                         i
    DECLARE
       v_starttime  TIMESTAMP;
       v_endtime    TIMESTAMP;
    BEGIN
       v_starttime := SYSTIMESTAMP;
       dbms_lock.sleep(10);
       v_endtime := SYSTIMESTAMP;  
       INSERT INTO mylog VALUES (v_starttime, v_endtime,' || i || ');
       COMMIT;
    END;');
       END LOOP;
       COMMIT;
    END;
    -- This will set maximum number of jobs at the same time
    ALTER SYSTEM SET job_queue_processes=10;
    -- Submitting the jobs
    BEGIN
       FOR c1 IN (  SELECT *
                      FROM myjobs
                  ORDER BY id)
       LOOP
          -- Delete the job if it is already existing with the same name
          BEGIN
             DBMS_SCHEDULER.drop_job ('test_sched_job_' || c1.id);
          EXCEPTION
             WHEN OTHERS
             THEN
                NULL;
          END;
          DBMS_SCHEDULER.create_job ( job_name => 'test_sched_job_' || c1.id
                                    , job_type => 'PLSQL_BLOCK'
                                    , job_action => c1.SQLCODE, enabled => FALSE);
          DBMS_SCHEDULER.run_job (job_name => 'test_sched_job_' || c1.id, use_current_session => FALSE);
       END LOOP;
    END;
    -- After all jobs have been completed
    -- this will show the start time of jobs
    -- 10 jobs at the same time have started as per setting
      SELECT *
        FROM myjobs
    ORDER BY starttime, id;
    /* Cleanup */
    DROP TABLE myjobs;
    DROP TABLE mylog;
    {code}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Oracle plsql stored procedure

    I want to write a procedure in which IN parameter will be a query [e.g. select * from employee] & I want to store the result of the query into OUT parameter...
    what will be the datatype for the OUT parameter & how to write the procedure??

    user10412263 wrote:
    this question was asked in interview of plsql...Idiotic question. An interviewer should determine if you know how to correctly use the tools in SQL and PL/SQL.. and not whether you know how to use it incorrectly. Even better - an interviewer should determine how you approach problems and how you will solve them using SQL and PL/SQL.
    Questions that need to answers directly from the manual? That is pretty useless as it is easy to use manuals as reference material and no-one memorises the entire manual. Simple example. A question about the syntax for a partition exchange (ALTER TABLE) is silly.. whereas a question about where, when and why you would use a partition exchange is critical. The former you can look up in the manual at anytime when coding partition exchanges. The latter is a skill that requires understanding Oracle concepts and correctly applying these.
    Remember this when you go for interviews. I realise one cannot always wait and choose the perfect job - but be careful landing in a job position where you will not grow your skills and knowledge because of an environment that values "+syntax knowledge+" higher than understanding and applying software engineering fundamentals and concepts.

  • How to execute a function in oracle plsql object, when object dies

    I have a plsql object with a member function as exec_last.
    I want this procedure to be called when plsql object is cleaned or when the session hosting this object dies.
    In C, we have a system call as atexit(). Is there any such feature in Oracle 10g or any workaround using embedded java.
    This feature is required to flush the contents stored in plsql table in the object to the database, when program exits.
    Thank you,
    Warm Regards,
    Navin Srivastava

    navsriva wrote:
    Is there any better way to implement this in memory caching. What is the buffer cache of Oracle? It is exactly that - a memory cache for data blocks. Both new blocks (created by inserting new rows) and existing blocks (used by selects, updates and deletes, and re-used (freespace) by inserts).
    The Oracle buffer cache is a very mature and sophisticated cache. Attempting to do it "+better+" than the db buffer cache in another software layer (like PL/SQL) is mostly a waste of time and resources.. and invariable introduces another s/w layer that simply increases the number of moving parts. This in turn usually means increased complexity and slower performance.
    Why use bulk processing in PL/SQL? The basic and fundamental answer to that is to decrease the context switching between the PL engine and SQL engine.
    When running PL code to insert data into SQL, that data needs to be passed to the SQL engine, the PL engine needs to perform a context switch to the SQL engine to allow it to process that data and perform the SQL instruction.
    If there are a 1000 rows to inserts, it means a 1000 context switches.
    Bulk processing makes the "+communication/data pipe+" between the two bigger. Instead of passing a single row's data to the SQL engine via a context switch, a bulk collection/array of a 100 rows is passed. There is now a mere 10 context switches required to push that 1000 rows from the PL engine to the SQL engine.
    You can do the same from any other SQL client... (remember, that PL itself is also a SQL client). You can, using C/C++ for example, do the exact same thing. When passing row data to the SQL engine to insert, pass a collection of a 100 rows instead of the data for a single row.
    The exact same benefits result as in PL/SQL. A bigger communication pipe, allowing more data to be transferred to/from the SQL engine, resulting in less context switching.
    Of course, a context switch ito C/C++ is a lot more expensive than in PL/SQL - as the PL engine sits in the very same physical process as the SQL engine. Using C/C++, this will usually be a separate process communicating with the SQL engine process across the network.
    The same applies to other languages, like Java, C#, Delphi, Visual Basic and so on.
    It does not make sense to introduce another s/w layer, the PL/SQL engine, and have the client "+insert+" rows into its memory structures... and then use the PL engine to "+flush"+ that to the SQL engine via a bulk process command.
    It will be faster, and more scalable, having the client language using bulk processing directly and dealing with the SQL engine directly.
    Simple example. What does the SQL*Loader program (written in C) use? It does not use PL as a proxy for moving data from a CSV file into a SQL table. It calls SQL directly. It uses bulk processing. It is very fast at loading data.
    There is an exception to this. When PL is used as a business processing and validation layer. Instead of the client code implementing that logic, it is done using PL. The client then no longer will manually add an invoice to the INVOICES table for example. It instead calls the AddNewInvoice PL/SQL procedure - and this procedure does all. It checks the customer code as valid. Ensures that there's stock available of the products being ordered on the invoice. Etc.
    But in this scenario, PL is not used a secondhand "buffer cache". It is used for what it has been designed for - a proper application layer inside the database.

  • Oracle PLSQL developer guidance needed

    Hi,
    I am working as a PLSQL developer since last 3 years ,have a oracle certification on it. My current profile also includes
    dba activities related to development and test databases.
    Wanted to ask if i continue further in plsql would doing a oracle dba certification be helpful for my career.
    Also that after a couple of years in plsql what would be my profile and if i went for a dba profile now then what would be my profile.
    Seniors please guide.
    Thanks.

    A-K wrote:
    Hi,
    I am working as a PLSQL developer since last 3 years ,have a oracle certification on it. My current profile also includes
    dba activities related to development and test databases.
    Wanted to ask if i continue further in plsql would doing a oracle dba certification be helpful for my career.
    Also that after a couple of years in plsql what would be my profile and if i went for a dba profile now then what would be my profile.
    Seniors please guide.
    Thanks.bigdelboy is not a senior, merely a bigdelboy ... thoug I suppose as he was talking about ICL4130's today his age may be showing a little.
    As you have a PL/SQL I assume (possibly incorrectly) it is a PL/SQL OCA certification. In that case you should ensure you get a PL/SQL OCP first to demonstrate a high level of competence in that area.
    After that you may feel that a DBA certifcatiion may be helpful it towards some of the 'DBA' takes you are doing. 'DBA' covers a whole load of things, so its difficult to say how relevant the OCA would be for you. But a different way of looking at it is that self studying for a DBA probably wouldn't do much harm and you would learn cosething is the self study. But having said that you might want to review other things to look at:
    (1) Make sure you have done the 2 day dba course (and sit the exam also. You would get a cert but you might get a useful exam pass and it might be relevant to what you are doing).
    (2) Make sure there isn't something else you should be doing instead. The SQL OCE would be one thought. Or perhaps something completely different like UML. Or maybe some of the SOA stuff. Or maybe things that are not certifable like SQL statement tuning, or database security things, or Business intelligence .....
    The things I've mentioned are not directly career moved focused, so in that sense I probably havan't answered your question.
    Rgds - bigdelboy.

Maybe you are looking for