Running multiple queries in parallel in a stored procedure

Hi,
I have two queries one on table1 (group bys) and second on table2 (again group bys) and then I need to compare the results.
Is it possible to execute both of them in parallel as they have no dependencies ? SInce it is going to be called from a JAVA program right now the only way I know is
to execute them in multiple threads but it would be great to have ideas of how to do it in a stored procedure. As a series of steps(all sql quries) have to be carried out and
the data has to be locked for that period ?
Just for clarity the steps are :
Step1 : select for update cursor to lock the rows from table1
Step2: open curosr then select data from table1 --- perform validations
Step3 : select data using group bys on table1 and select data using group bys on table2 ---- this needs to be done in parallel (just to gain on time)
Step4 : compare data
Step5 : insert statement
Step6 : close cursor then commit and exit
This might be really silly question but please pardon my ignorance as I am not much of SQL guy !
Thanks,
Neetesh
Edited by: user13312817 on 10 Nov, 2011 8:27 AM

Maybe something like this (not tested)?
SELECT t1.referenceno
     , t1.col1
     , t1.col2
     , t1.entityparent
     , t1.class
     , t1.annual - t2.annual
FROM   (
          SELECT table1.Referenceno
               , table1.col1
               , table1.col2
               , entitycodes.entityparent
               , classes.class
               , SUM(nvl(table1.AnnualAmt,0)) as Annual
          FROM   table1
          JOIN   entitycodes ON entitycodes.entitycode = table1.fundentity
          JOIN   classes     ON classes.accountcode    = table1.account
          GROUP BY table1.Referenceno
                 , table1.col1
                 , table1.col2
                 , entitycodes.entityparent
                 , classes.class
     ) t1
JOIN    (
          SELECT table2.Referenceno
               , table2.col1
               , table2.col2
               , entitycodes.entityparent
               , classes.class
               , SUM(nvl(table2.AnnualAmt,0)) as Annual
          FROM   table2
          JOIN   entitycodes ON entitycodes.entitycode = table2.fundentity
          JOIN   classes     ON classes.accountcode    = table2.account
          GROUP BY table1.Referenceno
                 , table1.col1
                 , table1.col2
                 , entitycodes.entityparent
                 , classes.class
     ) t2 ON  t2.referenceno  = t1.referenceno
          AND t2.col1         = t1.col1
          AND t2.col2         = t1.col2
          AND t2.entityparent = t1.entityparent
          AND t2.class        = t1.class

Similar Messages

  • Running a Corba Client as a Java Stored Procedure

    Hi,
    I�m trying to use a Java Stored Procedure running as a Corba Client. I want to use the built in Visibroker ORB on Oracle side and JacORB (or others) on the server side.
    How can I init the ORB and get a naming service running not in Oracle but on the server side? Also which jar�s do I need to load into the db with (loadjava) to run the visibroker orb inside the Java Stored Procedure Client?
    I�m using Oracle 8.1.7.
    Thanks for help ;)

    By the way I�m using ORACLE 8.1.7.

  • How to run multiple queries in a report 6i

    hi!
    i have multiple queries that i have created in data model
    how can i invoke them in my report?
    thanks!

    Every query is run automatically. You can have a Q1 and Q2 and display results of Q1 on one page, and the results of Q2 on another.

  • Running Multiple Scenarios in Parallel

    Hello all,
    I am trying to figure out how to execute multiple Interfaces / Scenarios inside a single parent thread I found some useful guidance in the thread below.
    Link: Running multiple interfaces within a package in parallel
    Which lead to me to use ODIStartScen in Asynchronous Mode. This works for the most part but this method generates a new Session Number for every child thread. Is there a way to run the child sessions inside the parent?
    Thanks in advance
    Mike

    Hi Mike,
    The child sessions are always tagged to the parent sessions. You can find this in the Work Repos table in snp_session table, field name is parent_sess_no.
    To keep the same session-id even in the parent, try the below:
    1. Declare a variable with the refresh mode as 'select '<%=odiRef.getInfo(SESS_NO")%>
    2. Refresh this variable in the Parent Package.
    3. In all the child packages, just declare this variable. This will help ODI in identifying the variable and as the value is already refreshed, it will be used during execution.
    4. Use this variable and do what you are interested in.
    Hope this helps.
    Thanks,
    Nithesh B

  • How can I run multiple midlets in parallel via the raspberry pi cmd line interface?

    I am trying to run multiple midlets at the same time on my raspberry pi.
    From netbeans point of view I am able to deploy and run them. But for my applications I want to auto start multiple midlets on the raspberry pi.
    On the cmd line interface of java me 8 I have commands to install a midlet and run a midlet.
    But i am not able to start multiple midlets.
    Can someone explain to me how I can do this?

    Hi!
    Could you please clarify a bit: do you want auto-start behavior of your applications or be able to start them manually via CLI?
    Because "auto start" means that applications are started by Java once you start Java itself and in order to make it happen you shall mark your applications appropriately (check MEEP spec for "MIDlet-<n>-Type" application attribute value "autostart"). If this is the case, have you added this attribute?
    If you want to run them manually you should be ale to do so via CLI just the same way as you start one application (via "ams-run" command).
    Either way, could you also please clarify what are the symptoms of the problem? E.g. on CLI what are the messages you receive back (if start is unsuccessful what is the error message etc).
    In addition please mind that there is limit on number of simultaneous VM tasks. If I'm not mistaken by default it is 6: 2 of them are used by system code and each running MIDlet consumes 1 VM task. If you want to increase it please change the value of "MAX_ISOLATES" property in jwc_properties.ini file. The maximum supported value is 16
    Regards,
    Andrey

  • SQL Queries in Code V/s Stored Procedures

    Hi Friend,
    Can any one of you guide me with following..
    What is faster ? using SQL Queries in Java code or using Stored Procedures which are called from code?
    I understnd Stroed Procedures are faster and definitely it provides more maintainability.
    If any one can give me any links or resources which outlines pros and cons of using Stored Proc and SQL Queries embedded in Java than it would be a great help..
    If there are any articles which proves either of the above is a preferred way, that would also help..
    Appreciate the effort in advance !!
    Thanks
    Gurudatt

    Well one benefit of Stored Procs is that you "compile" it on the database whereas you might build your query on the fly in java... test coverage is important in order not to have such things as a typo in a column name....
    Still, if you change a table, you have to go through all the procedures in SQL and likely to do so in some of your business object... and trust me, that can be hell!
    It all depends on the use of the app...
    From my experience, Stored procedure are much faster than built-on-the-fly SQL (and quite faster than prepared statements depending on the JDBC driver, the re-use of connections etc...)....
    IMHO, you'd probably be wise to start of with prepared statements, and when the schema seems stable enough (ie unlikely to change), look for the slower queries and convert them to stroed procedures.
    If you don't have to support several databases and are tight on performance, you can even include some logic in your stored procedure (e.g. update several tables, based on various selects...etc...). The language is usually quite powerful, and that can save you the run-time of selecting, converting to object , process and update (i.e. several roud-trip between DB and app)...
    Tshcuss!
    Chris

  • Insert Multiple records using Database adapter with Stored procedure func

    Hi All,
    I want to insert multiple records on a database using a stored procedure. I wanted to insert those records using a Database Adapter and the Database adapter should be invoked by a Mediator.
    Can somebody suggest me with ideas whether it can be acheived with OOB capabtilities in SOA suite or not?
    Thanks for your help in advance.
    Thanks,
    Shiv

    The use case you want to achieve is feature supported by the DBAdapter and it is possible to invoke the same from mediator.
    Please have a look at the oracle documentation and you should be able to get the necessary information.
    The below links should help you as well:
    http://download.oracle.com/docs/cd/E15523_01/integration.1111/e10231/adptr_db.htm
    http://blogs.oracle.com/ajaysharma/2011/03/using_file_adapter_database_adapter_and_mediator_component_in_soa_11g.html
    There are some video tutorials as well :)
    http://www.youtube.com/watch?v=dFldS-fDx70 This should also help
    Thanks,
    Patrick

  • Collection-Inserting multiple rows in single shot within stored procedure

    Hello,
    Below are the data for rows that I want to insert into CUSTOMER_PRODUCT table from a stored procedure.
    Instead of making round trips twice to insert these two rows, I looking for a way to pass in the data for both those rows and then insert them from within the stored procedure in one shot.
    The stored procedure will be invoked by Java and .NET.
    Sample Data for CUSTOMERPRODUCT:_*
    ROW 1:
    CUSTOMER_ID : 1000
    PRODUCT_TYPE : PROD123
    IS_MEMERSHIP : Y
    IS_EMAIL_SUBSCRIPTION: Y
    ROW 2:
    CUSTOMER_ID : 1001
    PRODUCT_TYPE : PROD123
    IS_MEMERSHIP : Y
    IS_EMAIL_SUBSCRIPTION: Y
    Question 1:
    Which is the best way to do it?
    Question 2:
    Should collection be used? (or) is there any other approach that could be utilized?
    Question 3:Can you please provide a sample?
    Question 4:
    Are there any performance concerns in passing collection and iterating it to fetch value to insert into CUSTOMER_PRODUCT table?
    I'm running Oracle 10g.
    Thanks!

    user8291616 wrote:
    >
    Question 3:Can you please provide a sample?
    A sample in PL/SQL. /* Exceptions are not handled...*/
    SQL> create table test_customer
      2  (customer_id varchar2(10),PRODUCT_TYPE varchar2(10),
      3  IS_MEMERSHIP varchar2(1),IS_EMAIL_SUBSCRIPTION varchar2(1));
    Table created.
    SQL> create or replace package test_package is
      2     type cust_tab is table of test_customer%rowtype;
      3    procedure insert_customer(p_cust_dtls cust_tab);
      4  end;
      5  /
    Package created.
    SQL> create or replace package body test_package is
      2    procedure insert_customer(p_cust_dtls cust_tab) is
      3    begin
      4      forall i in 1..p_cust_dtls.count
      5          insert into test_customer
      6          (customer_id,PRODUCT_TYPE,IS_MEMERSHIP,IS_EMAIL_SUBSCRIPTION)
      7          values(p_cust_dtls(i).customer_id,p_cust_dtls(i).PRODUCT_TYPE,
      8                 p_cust_dtls(i).IS_MEMERSHIP,p_cust_dtls(i).IS_EMAIL_SUBSCRIPTION);
      9    end;
    10  end;
    11  /
    Package body created.
    --Calling the same in PL/SQL. You will do this part in JAVA..
    SQL> declare
      2    lt_cust test_package.cust_tab := test_package.cust_tab();
      3  begin
      4    lt_cust.extend(2);
      5    lt_cust(1).customer_id := '1000';
      6    lt_cust(1).PRODUCT_TYPE := 'PROD123';
      7    lt_cust(1).IS_MEMERSHIP := 'Y';
      8    lt_cust(1).IS_EMAIL_SUBSCRIPTION := 'Y';
      9    lt_cust(2).customer_id := '1001';
    10    lt_cust(2).PRODUCT_TYPE := 'PROD123';
    11    lt_cust(2).IS_MEMERSHIP := 'Y';
    12    lt_cust(2).IS_EMAIL_SUBSCRIPTION := 'Y';
    13    test_package.insert_customer(lt_cust);
    14    commit;
    15  end;
    16  /
    PL/SQL procedure successfully completed.
    SQL> select *
      2  from test_customer;
    CUSTOMER_I PRODUCT_TY I I
    1000       PROD123    Y Y
    1001       PROD123    Y Y

  • Running Multiple queries in Oracle 10g Express Edition! Help Me!

    I am new to Oracle 10g Express Edition.
    I used my browser to navigated to http://127.0.0.1:8080/apex
    I saw the database page.. logged in.. went into the SQL section.. now am not able to run two or more queries at the same time.. i have given a screenshot too. Plz.. check it and reply me quickly..
    http://i71.photobucket.com/albums/i149/prasanna7287/546895215.jpg
    Help me plz..
    Prasanna.

    There are two possibilities:
    1) Run the SQL commands, one command at a time;
    2) Create a script of multiple commands, and run the script.
    These are discussed in some detail in the online documentation at http://www.oracle.com/pls/xe102/homepage
    In particular, look at
    http://download-east.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25108/xedev_sql.htm#BJEIEIFJ
    Message was edited by:
    Hans Forbrich
    No ... wait ... please do not read the documentation! <g>

  • Running multiple jobs (or parallelism) in non-project mode

    So, I have just converted my GUI-based project mode project to Tcl based non-project mode.
    I have 8 OOC IP modules that I sythesise before the main design using synth_ip. This occurs sequentially, rather than in parallel as it could when I have a run for each module in the GUI. there I would just set the number of jobs to 8 upon launching the run. This was far quicker.
    Without creating runs for each IP, can I implement the same kind of parallellism with my non-project tcl script?

    No. There are sort of two issues.
    The first is that in non-project batch mode there is not (supposed to be) a mechanism for managing files and filesets. Each synthesis run that you want to run has its own set, and there would normally be no way (in non-project mode) of managing this within the Tcl environment. However, in the case of IP, this sort of isn't true - IP are almost by definition little projects, so this problem doesn't really apply here.
    The second is that in non-project mode, there is a single flow of execution - there is no concept of "background jobs" which is what is used in project mode; there is a single thread of Tcl execution that runs linearly. The processes invoked by this thread may use multiple processors (the place_design and route_design processes do), but only one process is running at a time. Furthermore, in non-project batch, there is no eqivalent to fork/join (which is esstially what launch_runs/wait_on_run is).
    So, you have two choices. One is to compile the IP outside of your main Vivado run before you launch your main run - use your OS to launch 8 separate Vivado processes, each of which has its own script to compile one of your IP.
    The other is to compile the IP once, and keep the generated products around from run to run; your IP does not need to be synthesized each time - each synthesis run should end up with exactly the same netlist. You can even revision control the IP directory (with all its targets). This way, during "normal" runs, you skip the IP synthesis entirely and go straight to synthesizing your design.
    Avrum

  • How to run multiple queries in a workbook

    Hi,
    I have 3 queries in a workbook with the same variables. How can I refresh all the 3 queries when I change the variable value. It allows me to refresh only one query at a time but I need to refresh all the 3 queries at once whenever variable value changes.
    Thanks,
    Kal

    Prakash,
    Do you have any more information on where i would find the setting to;
    "Refresh individual queries within a workbook (Single DataProviderRefresh)"
    is it on the
    i) dataprovider setting
    ii) workbook setting
    iii) elsewhere?
    many thanks
    Ian

  • I am looking to use multithreading in order to run multiple tests in parallel on one UUT.

    I am looking to multithread multiple tests in paralllel on one UUT.  I looked in the main site and all examples are on zip files that I seem to not be able to successfully download from the site.  Does anyone have any file examples or white papers on this subject that I can view???
    Solved!
    Go to Solution.

    put one test in a sub sequence.  then call that subsequence using New Thread as the Execution Options:
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Pass multiple values with IN parameter in stored procedure

    CREATE TABLE VTEST_INSERT (
    MY_ID NUMBER,
    COLUMN1 VARCHAR2(50)
    --SELECT * FROM VTEST_INSERT;
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (1,'TEST1');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (2,'TEST2');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (3,'TEST3');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (4,'TEST4');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (5,'TEST5');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (1,'TEST6');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (2,'TEST7');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (3,'TEST8');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (4,'TEST9');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (5,'TEST10');
    CREATE OR REPLACE
    PROCEDURE VTEST_INSERT_SP(vid IN VARCHAR2,vname IN VARCHAR2)
    AS
    BEGIN
    DELETE FROM VTEST_INSERT WHERE MY_ID IN (vid);
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (vid,vname);
    END;
    EXEC VTEST_INSERT_SP(1,'TEST999');
    This all works fine above. But I want to be able to pass in multiple vname values. so something like:
    EXEC VTEST_INSERT_SP(1,'TEST999','TEST888','TEST777');
    all help appreciated. thank you.
    This would do multiple inserts each with the same vid and the different vname values.

    Try something like this
    SET SQLBLANKLINES ON;
    ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
    DROP TABLE vtest_insert;
    CREATE TABLE vtest_insert(vid NUMBER, vname VARCHAR2(20));
    INSERT ALL
       INTO vtest_insert(vid, vname) VALUES(1, 'aaaa')
       INTO vtest_insert(vid, vname) VALUES(1, 'bb')
       INTO vtest_insert(vid, vname) VALUES(1, 'cccccc')
       INTO vtest_insert(vid, vname) VALUES(2, 'ddd')
       INTO vtest_insert(vid, vname) VALUES(2, 'ee')
    SELECT * FROM "PUBLIC".dual;
    SELECT * FROM vtest_insert;
    CREATE OR REPLACE TYPE vnames_tab_ty IS TABLE OF VARCHAR2(20)
    SHOW ERRORS;
    CREATE OR REPLACE PROCEDURE vtest_insert_sp
       p_vid     IN  vtest_insert.vid%TYPE,
       p_vnames  IN  vnames_tab_ty
    AUTHID DEFINER
    IS
    BEGIN
       DELETE FROM vtest_insert WHERE vid = p_vid;
       FORALL idx IN p_vnames.FIRST .. p_vnames.LAST
           INSERT INTO vtest_insert(vid, vname) VALUES(p_vid, p_vnames(idx));
    END vtest_insert_sp;
    SHOW ERRORS;
    <<bk>>
    DECLARE
      vnames vnames_tab_ty;
      vid vtest_insert.vid%TYPE;
    BEGIN
      bk.vid := 1;
      bk.vnames := vnames_tab_ty('vn-01', 'vn-02', 'vn-03');
      vtest_insert_sp(p_vid=>bk.vid, p_vnames=>bk.vnames);
      COMMIT;
      bk.vid := 2;
      bk.vnames := vnames_tab_ty('vn-04', 'vn-05', 'vn-06', 'vn-07');
      vtest_insert_sp(p_vid=>bk.vid, p_vnames=>bk.vnames);
      COMMIT;
    END;
    SELECT * FROM vtest_insert;
    Which produces the following output
    Table created.
    5 rows created.
           VID VNAME
         1 aaaa
         1 bb
         1 cccccc
         2 ddd
         2 ee
    Type created.
    No errors.
    Procedure created.
    No errors.
    PL/SQL procedure successfully completed.
           VID VNAME
         1 vn-01
         1 vn-02
         1 vn-03
         2 vn-04
         2 vn-05
         2 vn-06
         2 vn-07
    7 rows selected.
    SQL>
    Regards,
    Dariyoosh

  • Run multiple statement at a time in a procedure without scheduler

    Dear,
    I create a procedure that have many select, insert, update statement. How can I execute all the sql statement at a time without using scheduler. Please help me.

    Dear,
    I create a procedure that have many select,
    insert, update statement. How can I execute all the
    sql statement at a time without using scheduler.
    create procedure p is
    e number;
    n varchar2(10);
    begin
    select 1000,'MWZ' into e,n from dual ;
    insert into emp(empno,ename) values (e,n);
    select 7788,'Scotty' into e,n from dual;
    update emp set ename=n where empno=e;
    end;
    /There I can do many select, insert and update at a time
    create or replace procedure p is
    begin
         merge into emp using (
           select 1000 e,'MWZ' n from dual
           union all
           select 7788,'Scotty' from dual
         ) on (empno=e)
         when matched then
           update set ename=n
         when not matched then
           insert (empno,ename) values (e,n);
    end;
    /But again, why do not you want to use dbms_job? You could maybe do this in java

  • Run Multiple SSIS Packages in parallel using SQL job

    Hi ,
    We have a File Watcher process to determine the load of some files in a particular location. If files are arrived then another package has to be kick-started.
    There are around 10 such File Watcher Processes to look for 10 different categories of files. All 10 File Watcher have to be started at the same time.
    Now these can be automated by creating 10 different SQL jobs which is a safer option. But if a different category file arrives then another job has to be created. Somehow I feel this is not the right approach.
    Another option is to create one more package and execute all the 10 file watcher packages as 10 different execute packages in parallel.
    But incase if they don’t execute in parallel, i.e., if any of the package waits for some resources, then it does not satisfy our functional requirement . I have to be 100% sure that all 10 are getting executed in parallel.
    NOTE: There are 8 logical processors in this server.
    (SELECT cpu_count FROM sys.dm_os_sys_info
    i.e., 10 tasks can run in parallel, but somehow I got a doubt that only 2 are running exactly in parallel and other tasks are waiting. So I just don’t want to try this  option.
    Can someone please help me in giving the better way to automate these 10 file watcher process in a single job.
    Thanks in advance,
    Raksha
    Raksha

    Hi Jim,
    For Each File Type there are separate packages which needs to be run.
    For example package-A, processes FileType-A and package-B processes FileType-B. All these are independent processes which run in parrallel as of now. 
    The current requirement is to have File Watcher process for each of these packages. So now FileWatcher-A polls for FileType-A and if any of the filetype-A is found it will kick start package-A. In the same way there is FileWatcher-B, which looks for FileType-B
    and starts Package-B when any of FileType-B is found. There are 10 such File Watcher processes.
    These File Watcher Processes are independent and needs to start daily at 7 AM and run for 3 hrs. 
    Please let me know if is possible to run multiple packages in parallel using SQL job.
    NOTE: Some how I find it as a risk, to run these packages in parallel using execute package task and call that master package in job. I feel only 2 packages are running in parallel and other packages are waiting for resources.
    Thanks,
    Raksha
    Raksha

Maybe you are looking for

  • Infoset Query

    Hello Experts, I have created a query on infoset in BI 7.0. Infoset is built on Cube and DSO. Both have data. And the infoset also has the expected query result data. But still when I ran the query I did not get data. I tried to run the query by usin

  • PDFs are not generated from Burst

    Hi all I am getting this error when i schedule my report to run: Document generation failed [INSTANCE_ID=V110APLFFC006.1305547398367] [OUTPUT_ID=1035][ReportProcessor]Error rendering documentoracle.xdo.servlet.scheduler.ProcessingException: [ReportPr

  • Can't edit narrator field for audiobooks in iTunes

    I noticed a new "narrator" field in iTunes for the Audiobook media kind, but I can't edit it. Also, I can't seem to edit the "Remember playback position" and "Skip when shuffling" options. I can fix the second issue by changing it to Music media kind

  • Very Urgent Weblogic server 6.1 DataSource

    Dear sir: the following succeed: java utils.dbping MSSQLSERVER4 sa sa Riskanalysis@perky:1433. So how can i make a connection pool using these parameters in the weblogic admin console.need i create a DataSource first and how? I do like this: URL:jdbc

  • CacheLoader load() method is getting invoked all the time

    The cache.get() method invokes the CacheLoader load() method if the key is not present in the cache. But the key is present in the cache already and when ever i invoke cache.get() it is invoking the load() method to get the data from DB. The expiry d