CF8 cfquery multiple sql statements
In CF8, when I run a cfquery against MS SQL 2005 with
multiple SQL statements, the query return the result of the first
statement not the last one as in CF7. The following code snippet
will cause an error because myID doesn't exist in qry. I know I
should set a "result" variable to get the identity key in CF8 but
we have some sites deployed in CF7. Before all sites migrate to
CF8, I would like to have a way to use the same code for both CF7
and CF8 so I don't have to maintain two versions. BTW, I tried
three datasourcr drivers: "Microsoft SQL Server", "Other" with
JDBC, and "ODBC Socket" with SQL Native Client. All of them gave
the same result. Please help. Thanks.
Hi Alex Pai,
Coincidentally, someone just asked a similar question
here.
So you might try searching the forums first. The query in the other
thread is slightly different, but the answer is the same.
Totally unrelated to your problem, but for SQL 2000/2005 you
should use scope_identity(), not @@identity.
Similar Messages
-
Multiple SQL statements in Init SQL in WLS 8.1
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do I seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxMahendra wrote:
Thanks Joe.
Following worked for Oracle 8.1.7Good news.
but did not for 8.0.6
SQL BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''MM/DD/YYYY''';
EXECUTE IMMEDIATE 'SET ROLE xxx identified xxx'; end;
Do you know 8.0.6 syntax ?You might try asking oracle, but note that no one is supporting that old version
of Oracle any longer...
Joe
>
Mahendra
Joe Weinstein <[email protected]> wrote:
Hi.
I found the syntax, I think. Try this:
BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = 'MM/DD/YYYY'';
EXECUTE IMMEDIATE 'SET ROLE <<role name>> identified
by <<pwd>>';END;
Joe
Mahendra wrote:
Still getting following exception.
<Feb 19, 2004 1:47:58 PM EST>
<Warning>
<JDBC> <BEA-001164>
<Unable to initialize connection in pool "XXXX".
Initialization
SQL = "BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole xxxx_role
identified by
xxxx; END;".
Received exception: "java.sql.SQLException: ORA-06550: line 1,column7:
PLS-00103: Encountered the symbol "ALTER" when expecting one of thefollowing:
begin declare exit for goto if loop mod null pragma raise
return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql commit <a single-quoted SQL string>
The symbol "update was inserted before "ALTER" to continue.
ORA-06550: line 1, column 61:
PLS-00103: Encountered the symbol "ROLE" when expecting one of thefollowing:
transaction
".>
<Feb 19, 2004 1:47:59 PM EST> <Notice> <WebLogicServer> <BEA-000355><Thread "Li
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
Thanks for reply, but that did not worked.
Get following exception
Unable to initialize connection pool "POOL_NAME".
Initialization SQL = "Select count(*) from ""SQL BEGIN alter sessionset nls_date_format
= 'MM/DD/YYYY'; set role xxx_role identified by xxxx; END;"". Receivedexception:
"java.sql.SQLException: ORA-00972: identifier is too long
Since we have not given SQL before that statement, BEA is treating
statment "SQL Begin ....." as a table name.
Then I tried by putting SQL out side quotes, like SQL "Begin .....end;" but the
same error.
Is there any way around it ?
MahendraHi. The full string you should enter into the console when you define
the
initSQL parameter is:
SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; set role
xxx_role identified by xxxx; END;
Let me know...
Joe
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do
I
seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxThis will always be DBMS-specific. If this is for oracle, you can
try:
"SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole
xxx_role identified by xxxx; END;"
Joe -
XML Publisher - can we specify multiple SQL statements in the report?
Hi there,
can we specify multiple SQL statements in the report with XML Publisher?
Regards,
LiviuCould we eventually generate with the Wizards available in XML Publisher desktop 5.6.2 an xml file with a structure like the one given below? The reason is to facilitate creation of the two rowsets. Thanks, Liviu.
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<ROWSET2>
<ROW2>
<FIELD1>Query1</FIELD1>
<FIELD2>field2</FIELD2>
<FIELD3>field3</FIELD3>
</ROW2>
</ROWSET2>
<ROWSET>
<ROW>
<FIELD1>Query2</FIELD1>
<FIELD2>field2</FIELD2>
<FIELD3>field3</FIELD3>
</ROW>
</ROWSET>
</DATA> -
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 -
Excuting multiple sql statements
Hi to everybody.
I'm quite new to Oracle even if i have quite a big experience with MySQL and SQL commands. I'm facing a problem that I suppose it is a really basic one.
I received a dump of an Oracle database in a .sql format. I mean that both the schema and the data are build through a large number of sql statements. In particular the schema is made through a lot of "create table ..." while the data are built through "insert into..". My need is to import these database in a fresh Oracle database Oracle 10 g XE.
I've installed it on a Debian system and i can succesfully execute a single SQL command both through the web interface http://localhost:8080/apex and logging as oracle user through the sqlplus username/passwd command.
My problem is that the data are split on about 12000 SQL "INSERT INTO.." so executing all of them one by one could be a little annoying :-)
<u>So I'm asking if there is a way to instruct Oracle to execute multiple SQL statements reading it from a file (like MySQL does for example).</u>
I' m considering to write a script to do it if there's no better way. I know that there're better way to dump databases in Oracle but I can change the .sql format since it is the only one that I got.in SQL*Plus you can execute a SQL file with the start command or it's shorthand version @:SQL> start filename.sql
or
SQL> @filename.sql -
Executing multiple SQL statements fails using ODBC
Executing multiple SQL statements will fail with error 'ORA-00911 invalid character' when connecting to an Oracle database using ODBC driver version 8.01.07.00.
When I use either my application or the Oracle ODBC Test client utility connecting using ODBC driver version 8.01.07.00 I can only get a single CALL statement (as shown below) to execute:
CALL BHInsert (TO_DATE('2003.07.23 10:04:28','YYYY.MM.DD HH24:MI:SS'),'BATCH_ID','1:CLS_FRENCHVANILLA-1','
','Event File
Name','\\KILLIANS\BATCHCTL\SampleDemo1\JOURNALS\1.evt','','AREA1','','','','','','1','','','','','',' ','');
When I try to execute the following string with multiple CALL statements (as shown below) it fails with the following error being returned - ORA-00911: invalid character
CALL BHInsert (TO_DATE('2003.07.23 10:04:28','YYYY.MM.DD HH24:MI:SS'),'BATCH_ID','1:CLS_FRENCHVANILLA-1','
','Event File
Name','\\KILLIANS\BATCHCTL\SampleDemo1\JOURNALS\1.evt','','AREA1','','','','','','1','','','','','',' ','');
CALL BHInsert (TO_DATE('2003.07.23 10:04:28','YYYY.MM.DD
HH24:MI:SS'),'BATCH_ID','1:CLS_FRENCHVANILLA-1','Version','Recipe Header','1.0','','AREA1',' ','
','','','','1','','','','','',' ','');
CALL BHInsert (TO_DATE('2003.07.23 10:04:28','YYYY.MM.DD
HH24:MI:SS'),'BATCH_ID','1:CLS_FRENCHVANILLA-1','Version Date','Recipe Header','5/18/2001 1:28:32
PM','','AREA1',' ',' ','','','','1','','','','','',' ','');
CALL BHInsert (TO_DATE('2003.07.23
10:04:28','YYYY.MM.DD HH24:MI:SS'),'BATCH_ID','1:CLS_FRENCHVANILLA-1','Author','Recipe Header','Mark
Shepard','','AREA1',' ',' ','','','','1','','','','','',' ','');
I've tried adding a line feed in addition to the space at the end of each call but that doesn't seem to help. Also have tried unsuccessfully to change the seperator used between each call using various valid continuation characters.
Executing multiple CALL statements from within Oracle's SQL Worksheet connecting as the same user and password, as my application executes successfully. However when I try this from within the Oracle ODBC test client, it fails with the same ORA-00911 error that I'm seeing in my application.
I'm currently trying the more recent ODBC drivers, however any ideas or suggestions would be greatly appreciated.Can you take the begin ... end block and run it using SQL*Plus?
I can't think of any documentation that would specifically answer this question. I'm sure if you read & absorbed the ODBC Programmers Reference (2000+ pages) you'd be able to find out, but I don't know of a quick way to find out.
You can enable SQL*Net tracing. There are a fair number of options for enabling this tracing-- http://tahiti.oracle.com has all the Oracle manuals online, which should give you enough info to configure exactly what you want.
I would suggest, however, that you look into more performant/ scalable alternatives rather than going too far down this path. A block with lots of SQL statements with literals isn't going to make your database happy even if you get it to work.
Justin -
Hey all
How do I create multiple sql statements? I know how to add a single line, but how do I efficiently insert multiple lines? Should I create a new string called "qry2" and then just add that to my executeUpdate statement?
//dbtest.jsp
String qry = "INSERT INTO item VALUES ('" postedItem "', '" stamp "');";
addStmt.executeUpdate(qry);You can have a separate variable, or you can just reuse qry.
As a side note, I strongly recommend you use PreparedStatement rather than Statement, and use its "?" parameters for the values you're going to insert: qry = "INSERT INTO item VALUES(?, ?)";
qry.setString(1, postedItem);
qry.setTimestamp(2, stamp); // or setString, or whatever type is appropriate for stamp -
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 -
Issue on execute multiple SQL Statement on MySQL
Hi,I plan to execute dozenes of INSERT SQL statement on MySQL by JDBC:org.gjt.mm.mysql.Driver,But it throws the unkown exeption,pls kindly help
The code is like the follwoing
sql="insert into TEST values('100','test') ";
stmt=cnMySQL.createStatement();
stmt.addBatch(sql);
stmt.addBatch(sql);
stmt.executeBatch();
//stmt.executeUpdate(sql);The Exception is very tough,paste for all
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:497)
at org.apache.jsp.testBean_jsp._jspService(testBean_jsp.java:293)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:484)
I have tried another way to execute multiple SQL.But the same Exception ocurred.
String sql="insert into TEST('100','100V'); "+
"insert into TEST('100','100V') ";
stmt.executeUpdate(sql);
Can't it the jdbc of MM support this kind of operation? And is there any better JDBC for mySQL?
Apprieciated for all!!! -
How to execute entire result set of multiple sql statements via sp_executesql?
I have a query that generates multiple insert statements (dynamic sql). So when I execute this my result set is a table of sql insert statements (one insert statment per row in my source data table). Like so:
Select 'INSERT INTO [dbo].[Table_1] ([Col1]) VALUES (' + SrcData + ')' from SourceDataTbl
How can I completely automate this and execute all these sql statements via sp_executesql?
My plan is to completely automate and execute all this via an SSIS package.
As always any help is greatly appreciated!
fyi- This is a very simple version of what I am trying to do. My query probably plugs in 20+ values from the SourceDataTbl into each of the sql insert statements.Ah, a small error in Visakh's post, which I failed to observe, and then I added one on my own.
DECLARE @SQL Varchar(max)
SELECT @SQL =
(SELECT 'INSERT INTO [dbo].[Table_1] ([Col1]) VALUES (' + SrcData +
')' + char(10) + char(13)
from SourceDataTbl
FOR XML PATH(''), TYPE).value('.', 'nvarchar(max)')
EXEC sp_executesql @SQL
Without ", TYPE" FOR XML returns a string when assigned to a variable. The TYPE thing produces a value of the XML data type, so that we can apply the value method and get string out of the XML.
And why this? Because:
DECLARE @str nvarchar(MAX)
SELECT @str = (SELECT 'Kalle Anka & co' FOR XML PATH(''))
SELECT @str
SELECT @str = (SELECT 'Kalle Anka & co' FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)')
SELECT @str
Although the data type is string when , TYPE is not there, it is still XML and characters special to XML are enticised.
Confused? Don't worry, for what you are doing, this is mumbo-jumbo.
Erland Sommarskog, SQL Server MVP, [email protected] -
From RSS into multiple sql statements
Hi all, I'm trying to import RSS into my database for this I
created an XSLT
stylesheet that transforms the XML into a series of SQL
statements like
below
INSERT INTO rss_feed(feed_title,feed_link,feed_description)
VALUES('','
http://...','');
SELECT @feed_id := MAX(feed_id) FROM rss_feed;
INSERT INTO
rss_channel(feed_id,channel_title,channel_link,channel_description,channel_language,chann el_copyright,channel_managingeditor,channel_webmaster,channel_pubdate,channel_lastbuilddat e,channel_generator,channel_docs,channel_cloud,channel_ttl,channel_image,channel_rating,ch annel_skiphours,channel_skipdays)
VALUES(@feed_id,'...','...','','','','','','','','','','','','','','','');
SELECT @channel_id := MAX(channel_id) FROM rss_channel;
INSERT INTO
rss_item(channel_id,item_title,item_link,item_description,item_author,item_comments,item_ guid,item_pubdate)
VALUES(@channel_id,'...','','...','Joris van Lier','','','');
SELECT @item_id := MAX(item_id) FROM rss_item;
INSERT INTO
rss_enclosure(item_id,enclosure_url,enclosure_type,enclosure_length)
VALUES(@item_id,'
http://...','...','...');
My problem is: I can pipe this into a command-line sql
session but when
executing it from PHP it gives me a sql syntax error, running
the statements
separately does not preserve the needed context with the
foreign key
variables.
Second problem: how do I select the last inserted id in
MySQL; is there an
equivalent to @@IDENTITY?
mysql Ver 14.7 Distrib 4.1.13, for unknown-linux-gnu (x86_64)
using
readline 4.3
Joris van Lier"David Powers" <[email protected]> wrote in message
news:fhrnou$j4g$[email protected]..
> Joris van Lier wrote:
>> I'm stuck with the standard MySQL extension in php,
>> however I noticed that phpMyAdmin reports the
following
>> MySQL client version: 4.1.13
>> Used PHP extensions: mysql <- notice there's NO
mysqli here,
>
> Have you checked phpinfo()? phpMyAdmin decides which
extension to use
> based on the settings in config.inc.php. If mysqli isn't
enabled, it
> sounds as though your server is still running PHP 4. If
so, that's crazy.
> Support for PHP 4 ends on December 31. It's time to
demand that your
> hosting company upgrades to PHP 5.2.
>
>> but it can execute my query
>> How do they do that?
>
> I have no idea how phpMyAdmin does it. I presume that it
uses explode() to
> separate the queries into an array, using the semicolon
as the separator.
> You can then loop through the array to execute each
query independently.
There's no mysqli support on this server, phpMyAdmin has an
internal parser
that splits the queries and tries to handle delimiters in
strings, and then
uses mysql_unbuffered_query or mysql_query, so it seems that
using one of
these functions with multiple consecutive queries preserves
the context of
the previous query.
Using explode will split strings that contain a semicolon,
I'm now trying
to escape the semicolons in strings to avoid writing my own
parser, so far
I've been thinking about HEXing them, but hexing complete
input will
seriously hurt my ability to read the queries, the
alternative CONCAT('foo',
0x3b, 'bar') still isn't pretty.
Do you know if it's possible to embed hexed characters into
strings (without
introducing a semicolon)?
Joris -
Multiple sql statements from java
I am executing sql statements in MaxDB 7.6.04.12 from java using jdbc.
I want to execute multiple statements at a time, but it seems that however I separate the statements, I get
com.sap.dbtech.jdbc.exceptions.DatabaseException: [-3014] (at 433): Invalid end of SQL statement
I have tried separating the statements with just a semi-colon, with a semi-colon and new line, with newline-//-newline (as works with SQL Studio), but whatever I try I get this error or some other.
Is it possible to do this? and if so how?
Thanks
ChrisHi Lars,
Here are the relevant bits of code.
However I'm not sure how helpful that will be - I'm using the SpringFramework for my jdbc calls, as it saves a lot of time and effort, and my calls are to Spring methods, which are wrappers round the base jdbc calls.
I'll post it anyway, just in case you're familiar with Spring. I haven't looked at the Spring code, but my understanding is it pretty much just passes the sql to standard jdbc calls.
I guess my next step would be to trace through the Spring code as it executes and see if anything becomes apparent. However I'm under some time pressure and was hoping to avoid that.
My other alternative is to create non-temporary tables, and drop them explicitly when I've finished with them.
public Set<String> getPriceUpdatedProducts() {
final Set<String> prods = new TreeSet<String>();
String sql;
int updates;
// need single connection template so subsequent statements can access temp tables:
JdbcTemplate jtSingle = getSingleConTemplate(jdbcTemplate);
// inDCs is a list of dist channels for an sql 'in' statement:
String inDCs = "";
for (String siteId: siteConfig.getAllSiteIds()) {
if (!"".equals(inDCs)) inDCs += ",";
inDCs += "'" + siteConfig.getSiteIdProperty(siteId, "distChanId") + "'";
// Clear all the changed flags from the last run:
updates = jtSingle.update("update zchangedartdc set changed = '' ");
// Get the current data into a temp table:
sql = "create table temp.pricechanges as " +
"select A304.matnr, A304.vtweg, konp.kbetr price " +
" from A304 join konp " +
" on A304.knumh = konp.knumh " +
" and A304.mandt = konp.mandt " +
" and A304.vkorg = '" + salesOrg + "' " +
" and A304.vtweg in (" + inDCs + ")" +
" and A304.kschl = '" + rrpCondType + "' " +
" and A304.mandt = '" + sapClient + "' " +
" and konp.kschl = '" + listCondType + "' " +
" and char(date, internal) >= chr(A304.datab) " +
" and char(date, internal) <= chr(A304.datbi) " +
" and A304.kappl = 'V' ";
jtSingle.execute(sql);
// Get the changes into a second temp table:
sql = "create table temp.changedarts as " +
"select temp.pricechanges.* " +
" from temp.pricechanges, zchangedartdc " +
" where zchangedartdc.matnr = temp.pricechanges.matnr " +
" and zchangedartdc.vtweg = temp.pricechanges.vtweg " +
" and zchangedartdc.price != temp.pricechanges.price ";
jtSingle.execute(sql);
// save the changes, and flag them:
sql = "update zchangedartdc " +
" set (price, changed) = (select price, 'X' " +
" from temp.changedarts " +
" where zchangedartdc.matnr = temp.changedarts.matnr " +
" and zchangedartdc.vtweg = temp.changedarts.vtweg) " +
" where matnr||vtweg in (select matnr||vtweg from temp.changedarts) ";
updates = jtSingle.update(sql);
// add the new items that weren't there last time, and flag them:
sql = "insert into zchangedartdc " +
"select '" + sapClient + "', matnr, vtweg, 'X', price " +
" from temp.pricechanges " +
" where matnr||vtweg not in (select matnr||vtweg from zchangedartdc) ";
updates = jtSingle.update(sql);
// now we've got all the changes flagged, we can get the list of changed products:
jtSingle.query("select distinct matnr from zchangedartdc " +
" where changed = 'X' ",
new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
prods.add(rs.getString("matnr"));
// release the connection:
destroySingleConnection(jtSingle);
return prods;
* Return a JdbcTemplate which will always use the same connection. Parameter jt is just
* a convenient way to get a DataSource from which to get a Connection.
* When the calling prodedure has finished, it MUST call
* destroySingleConnection(jt)
* @param jt
* @return
private JdbcTemplate getSingleConTemplate(JdbcTemplate jt) {
Connection con;
try {
con = jt.getDataSource().getConnection();
con.setAutoCommit(true);
} catch (SQLException e) {
throw new DataAccessResourceFailureException("Failed to get Connection for SingleConnectionDataSource", e);
SingleConnectionDataSource singleDs = new SingleConnectionDataSource(con, true);
return new JdbcTemplate(singleDs);
private void destroySingleConnection(JdbcTemplate singleConJt) {
try{
((SingleConnectionDataSource)singleConJt.getDataSource()).destroy();
} catch (SQLException e) {
throw new DataAccessResourceFailureException("Failed to destroy SingleConnectionDataSource", e); -
Executing multiple SQL statements
I'm using the SQL worksheet in JDeveloper to run SQL statements. JDeveloper won't run more than one statement at a time. Here's an easy example:
SELECT COUNT(*)
FROM TABLE1
WHERE PRICE IS NULL;
SELECT COUNT(*)
FROM TABLE1
WHERE PRICE > 0;
I get the following error when I submit multiple statements: ORA-00911: invalid character. I'm using the studio edition version 10.1.3.2.0.
Does Anybody know how to go around this or it is just that JDeveloper doesn't handle multiple statements?Hi,
I don't have a 10.1.3 instance to check currently. I suppose there would be an option to run script (along with run option).
Try this.
Open the SQL worksheet.
Type the statements.
SELECT COUNT(*)
FROM TABLE1
WHERE PRICE IS NULL;
SELECT COUNT(*)
FROM TABLE1
WHERE PRICE > 0;Select all (Ctrl+A), right click and see if you have a Run Script option in the context menu. If yes, select and it would work fine.
-Arun -
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 -
Spooling Extracts from Multiple SQL statements in 1 File
Hi all,
I am trying to spool extract results of 3 separate SQL statements into one single file. I wrote a SQL block similar to the one below. However, the result of the statements overwrite each other: 3 overwrote 2 and overwrote 1. Any suggestion how to combined there extracted results in one file?
spool c:\test.txt
<SQL statement 1>
<SQL statement 2>
<SQL statement 3>
/spool OFF
Thanks in advance
JasonPlease paste you SQL file here. These is no way one should overwrite another.
Eric
Maybe you are looking for
-
Just wanted to give a heads up about a review of the W530 that's written by a user who owns the W520, so it's heavy on comparisons which is kind of helpful if you're familiar with that machine. I'll quote the whole review below sans all the images t
-
New version 7.0.4 for iPhone 5s
Since I downloaded the new version 7.0.4 on my iPhone 5s, it seems to run very hot and the battery power does not last as long. Has anyone else had this problem since the new version was loaded?
-
Podcasts in Smart Playlist not showing up on iPhone in iOS 5
Upon first syncing my iPhone to iTunes after uploading both to iOS 5 and iTunes 10.5, I noticed that my podcasts in Smart Playlists were not there, and coincidentally, the Smart Playlists were gone in iTunes (that's a different issue altogether). The
-
I am curious, because having worked in a factory years ago that made foam products, it seems to me that foam is foam, and any high density slab of foam would do the trick, for a lot less money than these things cost. In my experience, there's maybe $
-
is there any way to provide One to many chatting on LAN. i am trying to do that but i am not able to construct the basic architecture that how actually it should work. if anybody who is having any idea that what should be the basic architecture of On