How to parallel execute in PL/SQL
in my statement, it need to do three work:
begin
execute immediate '......'; -- work 1
execute immediate '......'; -- work 2
execute immediate '......'; -- work 3
end;
how to let there work execute parallel?
What are the three statements doing? Is it something that Oracle could itself do via the SQL engine's parallel query functionality?
If not, you would have to submit three separate jobs (using DBMS_JOB or (in 10g and later) DBMS_SCHEDULER) that would run in three separate, parallel sessions using three separate transactions. If you need to wait for all three jobs to finish before continuing, you would also have to build some sort of interprocess communication code (which may be as simple as a table with process id's and state information that the parallel children update as part of their transaction and that the parent reads).
Justin
Similar Messages
-
How do I execute a returned sql string from a function on the command line?
Hi,
I have written a pl/sql function that will dynamically create a sql select statement. I need to be able to execute this statement from the command line. e.g from sqlplus
Say my function is called "sql_create" and it returns "select * from customer"
How do I execute the returned value from the command line?" Is it possible?
SQL> select sql_create from dual;
SQL_CREATE
select * from customer
SQL>
So I try:
SQL> exec execute immediate 'select sql_create from dual';
SQL>
I don't get an error but I don't get the result set either.
Is there a command I can use instead of execute immediate?
thanks,
Susan
Edited by: Susan123456 on Jul 2, 2009 1:21 AMdepends on the frontend. Most frontends (like Java and .Net) know how to handle REF CURSORS. Instead of returing a "string" which represents a query, return a ref cursor
SQL> ed
Wrote file afiedt.buf
1 create function sql_q return sys_refcursor
2 is
3 rc sys_refcursor;
4 begin
5 open rc for select * from emp;
6 return rc;
7* end;
SQL> /
Function created.
SQL> var r refcursor
SQL>
SQL> exec :r := sql_q
PL/SQL procedure successfully completed.
SQL> print r
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 900 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7566 JONES MANAGER 7839 02-APR-81 3075 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1350 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2950 30
7782 CLARK MANAGER 7934 09-JUN-81 2551 10
7788 SCOTT ANALYST 7566 19-APR-87 3100 20
7839 KING PRESIDENT 17-NOV-81 5100 10
7844 TURNER SALESMAN 7698 08-SEP-81 1600 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1200 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 1050 30
7902 FORD ANALYST 7566 03-DEC-81 3100 20
7934 MILLER CLERK 7782 23-JAN-82 1400 10 -
How to re-execute anonymous PL/SQL block in package definition ?
Hi all,
I implemented a package which contains procedures and an anonymous PL/SQL block.
This anonymous PL/SQL block is executed only once when the package is called.
and charge in-memory the content of table to avoid multiple SQL access each
time one procedure is called.
As my application open many sessions to the Oracle database, I would like to try
a solution to signal all sessions to reload the content of table when the content
of table is modified. The solution to stop and to restart the connection is not
acceptable.
Best regards
Sylvain> .. to avoid multiple SQL access each time one procedure is called.
As I understand your posting, this is the actual technical requirement. You want to force serialisation of PL/SQL code. Correct? (only one session at a time can run the procedure)
This feature typically used to accomplish this in o/s code is called a semaphore. PL/SQL does not specifically support semaphores. However, it supports a range of IPC (Inter Process Communication) methods - from message queues to pipes.
One of these IPC interfaces is DBMS_LOCK - which allows a unique lock to be defined and processes to manage their resource usage/execution/etc via this lock using the DBMS_LOCK API.
I've found this a pretty clean and manageable solution to enforce serialisation. Of course, it is even better not to enforce serialisation. Rather design the code to be thread safe and capable of multi-processing/parallel processing.
Personally, I would not use a table as an IPC mechanism as Oracle already provides better IPC mechanisms for PL/SQL code. As for "signalling sessions to re-load the table" - not possible as Oracle sessions cannot register callbacks to handle events. Oracle sessions are not event driven processes from a PL/SQL (application development) perspective. -
How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?
Hi
I have a stored procedure. It can be executed like this
exec test @p = 1;
exec test @p = 2
exec test @p = n;
n can be hundred.
I want the sp being executed in parallel, not sequence. It means the 3 examples above can be run at the same time.
If I know the number in advance, say 3, I can create 3 different Execution SQL Tasks. They can be run in parallel.
However, the n is not static. It is coming from a table.
How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?
I think about using script task. In the script, I get the value of n, and the list of p, from the table, then running a loop with. In the loop, I create a threat and in the threat, I execute the sp like : exec test @p = p. So the exec test may
be run parallel. But I am not sure if it works.
Any idea is really appreciated.Hi nam_man,
According to your description, you want to call stored procedures in parallel, right?
In SSIS, we can create separate jobs with different stored procedures, then set the same schedule to kick the jobs off at the same time. In this way, we should be careful to monitor blocking and deadlocking depending on what the jobs are doing.
We can also put all stored procedures in SSIS Sequence container, then they will be run in parallel.
For more information about SSIS job and Sequence container, please refer to the following documents:
http://www.mssqltips.com/sqlservertutorial/220/scheduling-ssis-packages-with-sql-server-agent/
https://msdn.microsoft.com/en-us/library/ms139855(v=sql.110).aspx
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu
Wendy Fu
TechNet Community Support -
How to execute procedure in SQL Worksheet ?
Hi, anybody know, how I can execute procedure here?
I try EXEC sec_roles, EXEC security_admin.sec_roles, EXECUTE - there is a SQL statement error. When I use CALL - there is no such procedure (I have execute previleges).
Although in SQLPlus EXEC works, but there are problems with standard SQL commands (all of them returns "2" no matter what content is).
Any ideas?
Regards
Krzysztofexec procedure(parameters) is a sql plus (and a few others) shortcut for
BEGIN
procedure(parameters);
END;So try that then pressing/clicking whatever it is in sql worksheet that makes a statement run.
Note that if your procedure has parameters defined as OUT or IN OUT, you will need to supply a variable to accept the returned value(s).
John -
How can I execute a Procedure with OUT variable is %ROWTYPE on SQL Prompt
Hi,
I have a procedure with OUT variable is %ROWTYPE
How can I execute the following procedure on SQL prompt.
(without creating anonymous block)
CREATE OR REPLACE PROCEDURE zz_sp_EMP(VEMPNO IN EMP.EMPNO%TYPE,
V_REC IN OUT EMP%ROWTYPE)
AS
BEGIN
SELECT * INTO V_REC FROM EMP WHERE EMPNO = VEMPNO;
END;
Thanks & Regards,
Nareshas previous posters said: it's not possible to do this without declaring a variable in the anonymous block.
With anonymous block it would look like this (had to change it a bit, since i'm using hr-schema on oracle XE):
declare
l_rec EMPLOYEES%ROWTYPE;
begin
zz_sp_EMP(VEMPNO => 100, V_REC => l_rec);
DBMS_OUTPUT.PUT_LINE ( 'first_name = ' || l_rec.first_name );
DBMS_OUTPUT.PUT_LINE ( 'last_name = ' || l_rec.last_name );
end;
first_name = Steven
last_name = King -
How to execute a PL/SQL in JAVA
I know how to execute a store procedure in PL/SQ. But how to execute a PL/SQL in JSP or other JAVA application?
Thank you!<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chin Chia Liang ([email protected]):
I know how to execute a store procedure in PL/SQ. But how to execute a PL/SQL in JSP or other JAVA application?
Thank you!<HR></BLOCKQUOTE>
You should use CallableStatement.
import java.sql.*;
class StoreProc
public static void main (String args [])
throws SQLException {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =DriverManager.getConnection ("jdbc:oracle:thin:@testing:1521:test1", "scott", "tiger");
//create procedure and call it in java (testproc)
CallableStatement cstmt = conn.prepareCall("{call testproc(?,?)}");
cstmt.setString(1, "teststore");
(2, "testagain");
cstmt.executeUpdate();
cstmt .close();
conn.close();
catch(SQLException e)
System.out.println("SQLException caught: " + e.getMessage()+" "+e.getErrorCode());
null -
How to get name of PL/SQL stored procedure being executed?
When executing a PL/SQL stored procedure, is there a way to extract the name of the procedure programatically?
(Similar to the way an Oracle Form can retrieve it's own name via GET_APPLICATION_PROPERTY(CURRENT_FORM_NAME). )
ThanksHere is one sample ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.17
satyaki>
satyaki>
satyaki>CREATE OR REPLACE PROCEDURE error_test1 AS
2 BEGIN
3 dbms_output.put_line(dbms_utility.format_call_stack);
4 END error_test1;
5 /
Procedure created.
Elapsed: 00:00:06.45
satyaki>
satyaki>
satyaki>exec error_test1;
----- PL/SQL Call Stack -----
object line object
handle number name
1D609C14 3 procedure SCOTT.ERROR_TEST1
1D5A89B8 1 anonymous block
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.21
satyaki>
satyaki>Regards.
Satyaki De. -
Parallel execution of PL/SQL procedures
Hi All,
I want to execute two PL/SQL procedures in parallel. Basically I want to execute one procedure in background and other procedure in foreground from a piece of PL/SQL code. How can I do that. Any help?See DBMS_JOB.
Richard -
How to attach .mdf file to sql server 2008 EXPRESS
I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
Any help??I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
Any help??
You are trying to attach SQL Server 2012 database files to SQL Server 2008 R2 which is not allowed, you either need to upgrade your SQL Server 2008 to 2012 or alternatively you can generate all scripts from SQL Server 2012 and execute it in SQL Server
2008 R2.
You can refer below link to how to generate script.
http://blog.sqlauthority.com/2012/07/18/sql-server-generate-script-for-schema-and-data-sql-in-sixty-seconds-021-video/
Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
Praveen Dsa | MCITP - Database Administrator 2008 |
My Blog | My Page -
How to see history in Oracle SQL
how to see history in Oracle SQL
i.e
create table.....
select * from tablename....
delete tablename;
Now i want to see how many command run after login.......please tell me the command...user12261139 wrote:
how to see history in Oracle SQL
i.e
create table.....
select * from tablename....
delete tablename;
Now i want to see how many command run after login.......please tell me the command...I'm not aware of an easy way to see how many commands were run after logging on. Different tools have different capabilities, though.
The ms-dos version of SQL*PLUS offers a Doskey option to use the up and down arrows to recover recently executed commands.
The SQL Workshop in Apex has a command history. Some of the GUI tools might offer similar functionality. -
Count (*) for select stmt take more time than execute a that sql stmt
HI
count (*) for select stmt take more time than execute a that sql stmt
executing particular select stmt take 2.47 mins but select stmt is using the /*+parallel*/ (sql optimer) in that sql command for faster execute .
but if i tried to find out total number of rows in that query it takes more time ..
almost 2.30 hrs still running to find count(col)
please help me to get count of row faster.
thanks in advance...797525 wrote:
HI
count (*) for select stmt take more time than execute a that sql stmt
executing particular select stmt take 2.47 mins but select stmt is using the /*+parallel*/ (sql optimer) in that sql command for faster execute .
but if i tried to find out total number of rows in that query it takes more time ..
almost 2.30 hrs still running to find count(col)
please help me to get count of row faster.
thanks in advance...That may be because your client is displaying only the first few records when you are running the "SELECT *". But when you run "COUNT(*)", the whole records has to be counted.
As already mentined please read teh FAQ to post tuning questions. -
Execute sqlldr command (Sql Loader) in PL/SQL
Hi guys... how can I execute this prompt command via PL/SQL command?
"sqlldr *****/******@ericsson control=nrcs_atelecom.CTL rows=100000 direct=true"
I have a lot of CTL files to process loading data. So, I create a PL/SQL that run a loop reading all CTLs, but I don´t know how run, via PL, the Sql Loader.I can't post a link but search the documentation, you'll find it in the "Utilities" manual.
Basically...you create tables that point to your files. Then you can SELECT from them like any other table. -
How to create CATALOG with MS SQL Server?
Connection class has getCatalog(strCatalog) method. In order to use it, we must create CATALOG in Database?
How to create CATALOG with MS SQL Server?
Help me, please!!!You do not create these for any database, this is part of the Connection metadata.
The Catalog is the third level of table-like database object qualification as in "Catalog.Schema.Table". For SQLServer the qualification scheme is "Database.Owner.Table" and I would be surprised if they reported anything for the current connections getCatalog() method call.
What many people do is avoid table qualification altogether by setting the connection's context in a database proprietary manner and then keeping the SQL as clean as possible. For many ODBC and JDBC drivers this can be set in the configuration. For MS SQLServer you can also execute a "USE dbname" statement on the connection to avoid table qualification. -
How to run execute immdiate with variables
Hi friends,
How to run execute immdiate with variables in v_stmt below?
I dont know how to declare the value of i here.
Set serveroutput on;
DECLARE
i VARCHAR (20);
v_stmt VARCHAR2 (100);
CURSOR c
IS
SELECT sqlid FROM temp1;
BEGIN
OPEN c;
LOOP
FETCH c INTO i;
EXIT WHEN c%NOTFOUND;
DBMS_OUTPUT.put_line (i);
v_stmt := 'select * from table(dbms_xplan.display_cursor('&i',null))'
execute immediate v_stmt;
END LOOP;
CLOSE c;
END;
/Regds,
Kunwar.You first need to use a bind variable (named ':v' in SQL statement in my example):
set serveroutput on;
DECLARE
i VARCHAR (20);
v_stmt VARCHAR2 (100);
CURSOR c
IS
-- modified for a quick test
SELECT sql_id FROM v$sql where child_number > 2;
BEGIN
OPEN c;
LOOP
FETCH c INTO i;
EXIT WHEN c%NOTFOUND;
DBMS_OUTPUT.put_line (i);
v_stmt := 'select * from table(dbms_xplan.display_cursor(:v,null))';
execute immediate v_stmt using i;
END LOOP;
CLOSE c;
END;
/However because your SELECT statement returns several rows you need to adapt your code to process all rows returned (as already suggested in first reply to your message).
Instead of using PL/SQL, I recommend to generate a SQL file using only SQL and then to run the generated SQL file.
For example:
spool edx.sql
set serveroutput on
declare
v_stmt varchar2(100);
v_q char(1):='''';
begin
dbms_output.put_line('spool edx.log');
for s in (select sql_id from v$sql where child_number >2)
loop
dbms_output.put_line('select * from table(dbms_xplan.display_cursor(' || v_q || s.sql_id || v_q || ',null));');
end loop;
dbms_output.put_line('exit');
end;
spool ofThis generates a SQL file similar to :
spool edx.log
select * from table(dbms_xplan.display_cursor('5rygsj4dbw6jt',null));
select * from table(dbms_xplan.display_cursor('5rygsj4dbw6jt',null));
select * from table(dbms_xplan.display_cursor('5rygsj4dbw6jt',null));
select * from table(dbms_xplan.display_cursor('fsbqktj5vw6n9',null));
select * from table(dbms_xplan.display_cursor('6q42j0018w7t8',null));
select * from table(dbms_xplan.display_cursor('a5mmhrrnpwjsc',null));
select * from table(dbms_xplan.display_cursor('3c1kubcdjnppq',null));
select * from table(dbms_xplan.display_cursor('3c1kubcdjnppq',null));
select * from table(dbms_xplan.display_cursor('9gkq7rruycsjp',null));
select * from table(dbms_xplan.display_cursor('f0wj261bm8snd',null));
select * from table(dbms_xplan.display_cursor('ab3swhv5g138y',null));
select * from table(dbms_xplan.display_cursor('6vgvyh4xw9c5g',null));
select * from table(dbms_xplan.display_cursor('ak5crjygnpk60',null));
select * from table(dbms_xplan.display_cursor('9p6bq1v54k13j',null));
select * from table(dbms_xplan.display_cursor('19x1189chq3xd',null));
select * from table(dbms_xplan.display_cursor('7sx5p1ug5ag12',null));
select * from table(dbms_xplan.display_cursor('730vdzhng6m6g',null));
select * from table(dbms_xplan.display_cursor('730vdzhng6m6g',null));
select * from table(dbms_xplan.display_cursor('0v3dvmc22qnam',null));
select * from table(dbms_xplan.display_cursor('0v3dvmc22qnam',null));
select * from table(dbms_xplan.display_cursor('a1zv6wju3ftgv',null));
select * from table(dbms_xplan.display_cursor('7ng34ruy5awxq',null));
select * from table(dbms_xplan.display_cursor('7ng34ruy5awxq',null));
select * from table(dbms_xplan.display_cursor('b2gnxm5z6r51n',null));
select * from table(dbms_xplan.display_cursor('b2gnxm5z6r51n',null));
select * from table(dbms_xplan.display_cursor('g4gp07gt2z920',null));
select * from table(dbms_xplan.display_cursor('1gu8t96d0bdmu',null));
select * from table(dbms_xplan.display_cursor('g00cj285jmgsw',null));
select * from table(dbms_xplan.display_cursor('g00cj285jmgsw',null));
select * from table(dbms_xplan.display_cursor('g00cj285jmgsw',null));
select * from table(dbms_xplan.display_cursor('bn4b3vjw2mj3u',null));
select * from table(dbms_xplan.display_cursor('38243c4tqrkxm',null));
select * from table(dbms_xplan.display_cursor('2abjfnvy5rkyg',null));
select * from table(dbms_xplan.display_cursor('350f5yrnnmshs',null));
select * from table(dbms_xplan.display_cursor('350f5yrnnmshs',null));
select * from table(dbms_xplan.display_cursor('3s1yukp05bzg6',null));
select * from table(dbms_xplan.display_cursor('3s1yukp05bzg6',null));
select * from table(dbms_xplan.display_cursor('1tgukkrqj3zhw',null));
exit
PL/SQL procedure successfully completed.Edited by: P. Forstmann on 20 mars 2013 19:06
Edited by: P. Forstmann on 20 mars 2013 19:33
Maybe you are looking for
-
I'm a new OEPE user, and found that after installing it, Eclipse (Kepler) now starts up with the wrong workspace every time. I have to explicitly do File > Switch Workspace... to get Eclipse to restart with the correct workspace. Also, the workspace
-
XSLT Mapping : RFC Lookup using java helper class
Hi All, I am doing RFC Lookup in xslt mapping using java helper class. I have found blog for the same (http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14) However this blog is very advanced. Can an
-
"install process encountered error while installing shared technology-adobe photoshop elements 12"
-
Full Screen Does Not Come Back After Minimizing Firefox to the Taskbar.
Full Screen Does Not Come Back After Minimizing Firefox to the Taskbar. I work in full screen almost exclusively ... the toolbar and the URL are still displayed while in full screen. Before this version (30.0), when I minimized Firefox to the taskbar
-
How to Apply sign flipping applied in Bex Query in Web i report
Hi, We have created a universe on top of Bex query and we have applied sign reversal to two of our rows in bex query, unfortunately when I run a report in webi the reversal of sign is not getting reflected in web i report. Could any one please help