How to execute multiple sql query in one time?
HI
I'm trying to convert my sql project In Oracle. In sql i could run multiple select statement/query in once and they return in multiple table result respectively. but in oracle its not executed.
like:
sqlQry := "Select * from abc; select * from qwe; select * from kkk; select * from xyz"
its return 4 table abc, qwe,kkk,xyz to my dataset result
how it is possible in oracle 10g
Saten Chamoli wrote:
I'm trying to convert my sql project In Oracle. In sql i could run multiple select statement/query in once and they return in multiple table result respectively. but in oracle its not executed.
like:
sqlQry := "Select * from abc; select * from qwe; select * from kkk; select * from xyz"
its return 4 table abc, qwe,kkk,xyz to my dataset result That is pretty much a hack - there are no ANSI SQL standards supporting this syntax. It makes no sense either.
If you want to combine 4 data sets, there are the UNION and UNION ALL set commands.
If you want to create 4 cursors with a single call, then use the following (anonymous PL/SQL block) call:
begin
open :c1 for select * from abc;
open :c2 for select * from qwe;
open :c3 for select * from kkk;
open :c4 for select * from xyz;
end;Bind 4 client cursor variables to the ref cursors c1 to c4 and make the call to Oracle.
And I suggest that you read up on Oracle concepts and fundamentals as your approach with you "sql project" shows ignorance in this regard.
Similar Messages
-
How to execute multiple sql statements
hi all
i am wondering if i can execute multiple sql statements in one shot with >> execute immediate command
for example:
i define the variable as X := sql statement
Y := sql statement
z := sql statement
can i do execute immediate (X,Y, Z);
if yes how ?? and if not any possible alternate
thanksStarting with Ganesh's code
DECLARE
l_statement VARCHAR2 (2000);
v_passwd VARCHAR2 (200);
v_username VARCHAR2 (200) := 'test';
v_pwd_key VARCHAR2 (200) := 'lwty23';
v_dblink_name VARCHAR2 (2000);
v_dblink_drop VARCHAR2 (2000);
v_dblink_create VARCHAR2 (2000);
v_dblink_check_connection VARCHAR2 (2000);
l_number NUMBER;
BEGIN
--<<c_instance>>
FOR c_instance IN (SELECT *
FROM v_oracle_instances
WHERE environment = 'Developement')
LOOP
SELECT encpwd_owner.display_db_encpwd (v_username,
c_instance.host_name,
c_instance.instance_name,
v_pwd_key)
INTO v_passwd
FROM DUAL;
v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name;
v_dblink_create :=
' CREATE DATABASE LINK '
|| v_dblink_name
|| ' CONNECT TO '
|| v_username
|| ' '
|| 'IDENTIFIED BY '
|| v_passwd
|| ' USING'
|| ' ''(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST= '
|| c_instance.host_name
|| ')(PORT='
|| c_instance.LISTENER_PORT
|| '))(CONNECT_DATA=(SID='
|| c_instance.instance_name
|| ')))''';
v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM'; --- Notice this change. I am simply selecting 1. That should be enough to test the database link.
v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF';
-- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;'
BEGIN
EXECUTE IMMEDIATE (v_dblink_create);
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created');
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name );
dbms_output.put_line( dbms_utility.format_error_backtrace() );
INSERT INTO error_table( column_list )
VALUES( <<list of values>> );
END;
EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number; --- Notice this.
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
BEGIN
EXECUTE IMMEDIATE (v_dblink_drop);
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name );
dbms_output.put_line( dbms_utility.format_error_backtrace() );
INSERT INTO error_table( column_list )
VALUES( <<list of values>> );
END;
END LOOP;
END;But I agree with the point that others have brought up that it really doesn't make sense to create and drop a database link like this.
Justin -
How to execute an SQL query present in a string inside an ABAP program?
hello,
How to execute an SQL query present in a string inside an ABAP programRaut,
You can execute Native SQl statements.
Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
EXEC SQL [PERFORMING <form>].
<Native SQL statement>
ENDEXEC.
There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
EXEC SQL PERFORMING loop_output.
SELECT connid, cityfrom, cityto
INTO :wa
FROM spfli
WHERE carrid = :c1
ENDEXEC.
Pls. Mark If useful -
How to execute this SQL Query in ABAP Program.
Hi,
I have a string which is the SQL Query.
How to execute this sql Query (SQL_STR) in ABAP Program.
Code:-
DATA: SQL_STR type string.
SQL_STR = 'select * from spfli.'.
Thanks in Advance,
VinayHi Vinay
Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
REPORT dynamic_sql_example .
DATA: BEGIN OF gt_itab OCCURS 1 ,
line(80) TYPE c ,
END OF gt_itab .
DATA gt_restab TYPE .... .
DATA gv_name(30) TYPE c .
DATA gv_err(120) TYPE c .
START-OF-SELECTION .
gt_itab-line = 'REPORT generated_sql .' .
APPEND gt_itab .
gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
APPEND gt_itab .
gt_itab-line = SQL_STR .
APPEND gt_itab .
gt_itab-line = 'ENDFORM.' .
APPEND gt_itab .
GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
IF FOUND .
WRITE:/ gv_err .
LOOP AT gt_result .
WRITE:/ .... .
ENDLOOP .
*--Serdar -
How to execute a sql query in VO????
Hi every body.
Can you show me the way to execute a sql query in VO.
For example: I have a viewobject1, and I add a new method void execSQL() before the last '}' of the java file of viewobject1 like this:
public void execSQL() {
String strSql = "Select sysdate from dual";
I want to execute strSql query and return a Resultset, how can I perform ???
Thanks a lot.The executeQuery method in ViewObjectImpl does not return a ResultSet.
ViewObjectImpl voImpl;
voImpl.setQuery(strSql);
voImpl.executeQuery(); -
How to execute multiple SQL statements thru frontend?
With SQL Server database, you can execute multiple SQL statements.
Ex.
SQLCommand cmd = new SQLCommand();
cmd.CommandText = "SELECT * FROM EMP; SELECT * FROM DEPT";
cmd.ExecuteXXX();
Note that for SQL Server, ";" (semocolon) is used as a separator.
What separator is required for Oracle ? Or rather, can I execute multiple SQL statements against Oracle database (10g) ?
(Why I want to do it is a totally diff. subject !)
Thanks,
Ami.Hello,
You could use an anonymous PL/SQL block to batch multiple statements.
If you want to use SELECT statements, you would open a REF CURSOR for each SELECT and return the REF CURSOR to your application. INSERT, UPDATE, and DELETE statements can just be passed as is.
A simple REF CURSOR example might look like:
begin
open :v_refcursor1 for select * from emp;
open :v_refcursor2 for select * from dept;
end;Where v_refcursor1 and v_refcursor2 are parameters defined as a REF CURSOR type.
Hope that helps a bit...
- Mark -
How to uninstall multiple cloud apps at one time?
How do I uninstall multiple cloud apps at one time from windows 7 pro?
Hi Bigdog3766,
Please refer to the below mentioned link under "Uninstall Apps":
http://helpx.adobe.com/creative-cloud/help/install-apps.html
Let us know if it helps,
Thanks!
Gurleen -
How to execute a SQL Query in Ms-Access
Hi,
I've a query which fetches the data from the tables based on daily transactions.
I mean, the data gets updated daily basis.
Now, i want to send the user a Ms-access work sheet with the query written, so that when ever the query is executed, it would fetch the records (with latest updates).
I found some documents in google to, how to write sql query in ms-access.
How ever, i'm unable to find the connection setup.
how do i connect to oracle database using ms-access??
Can any one please help me regarding this.
Thanks,
SanthoshYou can try this tutorials
http://www.reo.gov/gis/tools/infobase/LinkAccessToOracle.pdf
Basically steps include,
Install and configure Oracle client
Configure ODBC DSN using correct TNS name configured in first step
Link the table from Msaccess, make sure you linked the table not import it. -
How to execute multiple sql statements in parallel ?
Hi There,
I have 10 stored procedures, each one will take approximately 5 seconds to run individually.
Now I need to combine the results of these 10 stored procedures into single result set.
So I have created one more stored procedure "proc_AllSPs" to get the single result set.
The procedure "proc_AllSPs" is taking one minute to run because all the procedures inside the "proc_AllSPs" are running
one after the other and taking 5 seconds each.
If there is any other way that all the procedures run parallelly, then the procedure "proc_AllSPs" can run in 5 seconds time.
Sorry if I am not being elaborated.
PLease get back to me if any piece of information is needed.
Any kind of help is truly thankful.
Thanks,
SequelBugCould you tell me how to execute two stored procedures or two sql statements in parallel
For eg:
First procedure name is proc_sp1 which takes 1 minute to run
Second procedure name is proc_sp2 which takes 1 minute to run
I want to accomplish the below query in 1 minute by executing statement1 and statement2 parallelly.
go
select * from openrowswt('sqloledb','server','exec proc_sp1') --statement1
union
select * from openrowset('sqloledb','server','exec proc_sp2') --statement2
go
OR
go
Select * into #Temp1 from openrowswt('sqloledb','server','exec proc_sp1') --statement1
select * into #Temp2 from openrowset('sqloledb','server','exec proc_sp2') --statement2
Select * from #Temp1
UNION ALL
Select * from #Temp2
go
Thanks,
SequelBug -
How to execute multiple sql statement?
In an single transaction I want to execute two update statements. I don't know how to break those statements and send to oracle from Asp.Net to execute.
I tried go and ; .
Below is myQuery string*
update abc set One = 10 where Two = 3 ; update xyz set Three = 10 where Four = 3 ;
Additional info
I am using sql comment text in asp.net
I am using executenonquery command in asp.net.Hi,
If you want to execute multiple statements in a single transaction, you could either:
a) create a local transaction (via an OracleTransaction object), then call executenonquery multiple times within that transaction, or
b) pass them all in an anonymous block for a single round trip.. ie, begin update abc set One = 10 where Two = 3 ; update xyz set Three = 10 where Four = 3 ;end;
The database doesn't permit multiple statements passed at once (other than in a plsql block).
Hope it helps, corrections/comments welcome
Greg
PS, questions such as this would be better posted in the ODP.NET forum; this forum is for issues regarding ODT.NET (a VS plugin)
ODP.NET -
How to execute multiple sql statements in oracle?
I want to execute multiple statements in a single transaction in oracle. Following are my queries:
Create table temp_table as Select * from table;
SELECT * FROM temp_table d;
drop table temp_table ;
I am using sql comment text in asp.net
I am using executenonquery command in asp.net.
Thanks,
DivyaSigCle ,
Here's an example that executes 3 statements;
begin insert into foo values(1); insert into foo values(2); insert into foo values(3); end;
923354,
The block doesn't compile because temp_table doesn't exist at the point you're trying to compile the anonymous block. I'd recommend re-reading the doc link and forum link provided to get a better understanding of how temp tables work, as it's simply different with Oracle. You don't create Oracle temporary tables on the fly; you create them ahead of time and then just use them. The data itself is already specific to a particular session; you don't create and drop the table each time.
Also, you can't just "select * from table" in plsql. The results have to GO SOMEWHERE. Usually you'd either open a cursor and process it in the block, or send out a ref cursor if you want to send the data to a client side app. The ref cursor data wouldn't actually be fetched until the block completes though, so you'd need to use ON COMMIT PRESERVE ROWS, which would also mean you'd need to clean up the data yourself (delete the data from the table when you're done with it).
Corrections/comments welcome.
Greg -
Executing Multiple SQL queries in one connection
I'm trying to do, 2 queries in a single connection to my MySQL database.
At the moment I'm just passing a String into execute query.
I want to do another check in the database just after I get the first query's results.
Right now, I'm closing the connection and creating a whole new one again as it doesn't seem to work otherwise.
Do I just need to create a new "Statement" & "ResultSet" and then do my thing within the connection brackets?
I did that but was getting no response. Perhaps I'm missing something?
Code to SELECT all Documentaries from the database:
String getDocs = "SELECT * from podDir WHERE genre='Documentaries'";
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/jspod", "root", "pass");
System.out.println("got connection");
Statement s = con.createStatement();
ResultSet r2 = s.executeQuery(getDocs);
while (r2.next()) {
out.println("<TD>" + StringUtil.encodeHtmlTag(r2.getString(1)) + "</TD>");
out.println("<TD><A href='" + StringUtil.encodeHtmlTag(r2.getString(3)) + "'>" + StringUtil.encodeHtmlTag(r2.getString(2)) + "</a></TD>");
out.println("<TD>" + StringUtil.encodeHtmlTag(r2.getString(4)) + "</TD>");
out.println("<TD>Subscribe</TD>");
out.println("</TR>");
out.println("<TR><TD></TD><TD>" + StringUtil.encodeHtmlTag(r2.getString(6)) + "</TD>");
out.println("</TR>");
r2.close();
s.close();
con.close();
catch (SQLException e) {
catch (Exception e) {
}Thanks ram..
I'm now finding I'm facing a situation, however where
I need two executions ongoing at one time.
I need to select all listings from a directory table
and then check if the person logged in has subscribed
to that listing from a "Mysubs" table concurrently to
display "You are/not subscribed to this
listing".
Is it possible to have two ongoing executions?Some would prefer to do all that in a single query - but then one has to be pretty good in sql for that.
You can do the stuff with 2 or more queries too. Open a Connection, create a PreparedStatement(or a Statement) with your first query for the listings. Get the result set, hold the output in a ListingModel object. You would then close the result set and the statement and then open new ones for your second query which can be supplemented with data from the model object. Or you can retrieve the entire data and compare with the listing info in the ListingModel object. Close everything in a finally block.
ram. -
How to know which sql query is taking time for concurrent program
Hi sir,
I am running concurrent program,that is taking time to execute ,i want to know which sql query causing performance
Thanaks,
SreekanthHi,
My Learning: Diagnosing Oracle Applications Concurrent Programmes - 11i/R12
How to run a Trace for a Concurrent Program? (Doc ID 415640.1)
FAQ: Common Tracing Techniques in Oracle E-Business Applications 11i and R12 (Doc ID 296559.1)
How To Get Level 12 Trace And FND Debug File For Concurrent Programs (Doc ID 726039.1)
How To Trace a Concurrent Request And Generate TKPROF File (Doc ID 453527.1)
Regards
Yoonas -
How to get report (SQL Query) generating Run Time
There is a Standard report of Payroll which show employee transfer information on the bases of location, grade job or organization, now to get actual query which is generated by run time in report builder including whether single column parameter or lexical parameter " because currently the query in not complicate but the parameter and lexical parameter is much more due to this not quite easy to under stand just copy past it into toad or pl/sql developer,
Kindly share your experience to get such kind of query in you working time.
thanksHere i try to explain contain of query.
Parameter
P_DEPTNO = 10
P_WHERE_CLAUSE := ' AND EMPNO IS NOT NULL AND SALARY > 100'
SELECT * FROM EMP
WHERE DEPTNO = P_DEPTNO
&P_WHERE_CLAUSE
REPROT WILL GENERATE QUERY AT RUN TIME IS LIKE THAT
SELECT * FROM EMP
WHERE DEPTNO = 10
AND EMPNO IS NOT NULL AND SALARY > 100
Now i want to get this query out(Run time) by doing any oracle database feature or sth similar.
thanks -
How to print multiple Delivery document at one time?
Hi experts,
Could you tell me how to print / re-print mulitple Delivery documents at one time?
VL02N could be only used to print 1 delivery documeny by document which is time consuming.
I could only remember the Transaction starts with VL ...but do not know it exactly.
Thanks,
PriHi
If you have already taken the printout for the deliveries ,kindly use the below selection criteria to reprint the same
t- code --VL71
Output Type - ABC
Transmission Medium - 1
Sort order - 01
Processing Mode - 02
1 First Processing
2 Repeat Processing
3 Error Processing (All)
4 Error Processing (Only New Messages)
Shipping Point - 1000
Delivery - Few Delivery docs
Output Device - My printer number
Regards
Damu
Maybe you are looking for
-
Error in decimal places while using the currency ends with 4 e.g. CNY4,USD4
Dear all, I need ye help, the problem that a report having a field KONP-KBETR .......the report moves the decimal 2 places to the right. And so, 412.3846 becomes 41238.46. ..occurs only when the currency ends in 4 (CNY4, USD4, EUR4..) Can yo
-
How do I backup itunes to enternal hard drive?
How do I backup my iTune library to an external harddrive? I have never done it before.
-
When i try to activate iphone it continues to say it is the wrong password
I did a factory reset and update on my iPhone 4 when I went to activate my phone will not accept my password please help
-
APEX 2.2 starting page.
Hi All, I install oracle application express on linux es4 with out any issues. Thank you for installing Oracle Application Express. Oracle Application Express is installed in the FLOWS_020200 schema. my opmn status is [oracle@abc bin]$ ./opmnctl stat
-
Exception thrown when start OC4J
Sometimes, I got the folloowing exceptions when I started OC4J. Exception Description: Several [9] SessionLoaderExceptions were thrown: Exception [TOPLINK-9005] (OracleAS TopLink - 10g (9.0.4.7) (Build 050405)): orac le.toplink.exceptions.SessionLoad