Home
Analytics
how to pass multiple sql query with oracle
ossvisor
I am porting one of birt report DB which has been using MSQL server to oracle ,, but looks like oracl DB engine is not accepting multiple sql query ... <br />
<br />
<br />
<span class='bbc_underline'><strong class='bbc'>this works ok in MSQL but not in oracle </strong></span><br />
<span class='bbc_underline'><br />
<strong class='bbc'>beforeopen dataset script </strong></span><br />
<br />
this.queryText = "INSERT into DBSNMP.EMAILADDRESSES (NAME,EMAIL) VALUES ('xyz','abcd')";<br />
<br />
this.queryText += " select * from DBSNMP.EMAILADDRESSES "<br />
<br />
//Packages.java.lang.System.out.println("Insert Statement is: " + this.queryText);<br />
<br />
<strong class='bbc'><br />
<span class='bbc_underline'>and if i comment the first line query does work in oracle </strong></span><br />
<br />
//this.queryText = "INSERT into DBSNMP.EMAILADDRESSES (NAME,EMAIL) VALUES ('xyz','abcd')"<br />
<br />
this.queryText = " select * from DBSNMP.EMAILADDRESSES "<br />
<br />
//Packages.java.lang.System.out.println("Insert Statement is: " + this.queryText);<br />
<br />
<br />
<br />
looks like unlike MSQL server oracle is not accepting the two this.queryText ....<br />
<br />
<br />
not sure what's wrong here ,,, <br />
<br />
is there any other optional way wher we can use multiple sql query to this.queryText......
Find more posts tagged with
Comments
mwilliams
From the above, I can't really tell what you're trying to do with your query. What does the entire query look like? Are you doing a union? Or what? Let me know.
ossvisor
this is how the dataset beforeopen script looks like .. it works perfect with MSQL server but does not work with oracle
//Get the report parameters
ParamName = reportContext.getParameterValue("Name");
ParamEmail = reportContext.getParameterValue("Email");
this.queryText = "INSERT into DBSNMP.EMAILADDRESSES (NAME,EMAIL) VALUES ('" + ParamName +"','" + ParamEmail + "')";
this.queryText += " select * from DBSNMP.EMAILADDRESSES where EMAIL = '" + ParamEmail +"'"
//Packages.java.lang.System.out.println("Insert Statement is: " + this.queryText);
alex520
maybe you can try to add a semicolon after your first statement, like :
xxxx + ParamEmail + "');";
hope it works.
ossvisor
@alex520
Icon
that was the first thought that striked me when i stuck in to this one ... i tried that but no luck ....
mwilliams
Nevermind my above post, I was looking at the first line wrong. I was looking at it as if both had += rather than the first being just =. Based on what I see now, it seems that you have the correct syntax for this. What is the error you're getting? Or is the result set just blank?
ossvisor
<strong class='bbc'>here is error output ... what i think is that for some reason oracle doesn't accept multiple query like msql server <br />
</strong><br />
<br />
16-Jun-2011 21:11:03 org.eclipse.birt.report.debug.internal.core.vm.ReportVMServer start<br />
INFO: [Server] client accepted<br />
16-Jun-2011 21:11:03 org.eclipse.birt.report.debug.internal.core.vm.ReportVMServer$1 run<br />
INFO: [Server] enter request dispatching<br />
16-Jun-2011 21:11:04 org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher configEngine<br />
INFO: User class path received: <br />
>>>> Compiled Source: /report/data-sets/oda-data-set[
@id="
;198"]/method[
@name="
;beforeOpen"]<br />
function __bm_beforeOpen() {<br />
//Get the report parameters<br />
ParamName = reportContext.getParameterValue("Name");<br />
ParamEmail = reportContext.getParameterValue("Email");<br />
<br />
<br />
this.queryText = "INSERT into DBSNMP.EMAILADDRESSES (NAME,EMAIL) VALUES ('" + ParamName +"','" + ParamEmail + "')";<br />
<br />
this.queryText += " select * from DBSNMP.EMAILADDRESSES where EMAIL = '" + ParamEmail +"'"<br />
<br />
Packages.java.lang.System.out.println("Insert Statement is: " + this.queryText);<br />
<br />
<br />
} <br />
>>>> end compilation.<br />
>>>> Compiled Source: /report/data-sets/oda-data-set[
@id="
;198"]/method[
@name="
;beforeOpen"]<br />
__bm_beforeOpen()<br />
>>>> end compilation.<br />
>>>> Frame Source Name: /report/data-sets/oda-data-set[
@id="
;198"]/method[
@name="
;beforeOpen"]<br />
>>>> Frame Function Name: __bm_beforeOpen<br />
>>>> Enter script. 2<br />
>>>> Line changed to: 2<br />
>>>> Line changed to: 3<br />
>>>> Line changed to: 6<br />
>>>> Line changed to: 8<br />
>>>> Line changed to: 10<br />
Insert Statement is: INSERT into DBSNMP.EMAILADDRESSES (NAME,EMAIL) VALUES ('newname','newemail') select * from DBSNMP.EMAILADDRESSES where EMAIL = 'newemail'<br />
>>>> Exit script.<br />
16-Jun-2011 21:11:19 org.eclipse.birt.data.engine.odaconsumer.PreparedStatement getRuntimeMetaData<br />
SEVERE: Cannot get the result set metadata.<br />
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.<br />
SQL error #1:ORA-00933: SQL command not properly ended<br />
<br />
;<br />
java.sql.SQLException: ORA-00933: SQL command not properly ended<br />
<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.executeQuery(Statement.java:471)<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.getMetaUsingPolicy1(Statement.java:410)<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.getMetaData(Statement.java:312)<br />
at org.eclipse.birt.report.data.oda.jdbc.bidi.BidiStatement.getMetaData(BidiStatement.java:56)<br />
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaQuery.doGetMetaData(OdaQuery.java:412)<br />
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaQuery.getMetaData(OdaQuery.java:379)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.getRuntimeMetaData(PreparedStatement.java:407)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.getProjectedColumns(PreparedStatement.java:377)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.doGetMetaData(PreparedStatement.java:347)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.getMetaData(PreparedStatement.java:334)<br />
at org.eclipse.birt.data.engine.executor.DataSourceQuery.getMetaData(DataSourceQuery.java:416)<br />
at org.eclipse.birt.data.engine.executor.DataSourceQuery.prepare(DataSourceQuery.java:336)<br />
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery$OdaDSQueryExecutor.prepareOdiQuery(PreparedOdaDSQuery.java:455)<br />
at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:340)<br />
at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:455)<br />
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190)<br />
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178)<br />
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:145)<br />
at org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.execute(DataRequestSessionImpl.java:616)<br />
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:152)<br />
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:265)<br />
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1890)<br />
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)<br />
at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)<br />
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)<br />
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)<br />
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)<br />
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)<br />
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)<br />
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:99)<br />
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:180)<br />
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.createReport(ReportLauncher.java:594)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.renderReport(ReportLauncher.java:541)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.run(ReportLauncher.java:455)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.main(ReportLauncher.java:104)<br />
at org.eclipse.birt.report.debug.internal.core.ReportDebugger.start(ReportDebugger.java:39)<br />
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)<br />
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)<br />
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)<br />
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)<br />
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)<br />
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br />
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br />
at java.lang.reflect.Method.invoke(Unknown Source)<br />
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)<br />
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)<br />
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)<br />
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)<br />
Caused by: java.sql.SQLException: ORA-00933: SQL command not properly ended<br />
<br />
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)<br />
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)<br />
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:590)<br />
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1973)<br />
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1119)<br />
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2191)<br />
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2064)<br />
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2989)<br />
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:658)<br />
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:584)<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.executeQuery(Statement.java:467)<br />
... 49 more<br />
16-Jun-2011 21:11:19 org.eclipse.birt.data.engine.odaconsumer.PreparedStatement getRuntimeMetaData<br />
SEVERE: Cannot get the result set metadata.<br />
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.<br />
SQL error #1:ORA-00933: SQL command not properly ended<br />
<br />
;<br />
java.sql.SQLException: ORA-00933: SQL command not properly ended<br />
<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.executeQuery(Statement.java:471)<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.getMetaUsingPolicy1(Statement.java:410)<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.getMetaData(Statement.java:312)<br />
at org.eclipse.birt.report.data.oda.jdbc.bidi.BidiStatement.getMetaData(BidiStatement.java:56)<br />
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaQuery.doGetMetaData(OdaQuery.java:412)<br />
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaQuery.getMetaData(OdaQuery.java:379)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.getRuntimeMetaData(PreparedStatement.java:407)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.getProjectedColumns(PreparedStatement.java:377)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.doGetMetaData(PreparedStatement.java:347)<br />
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.execute(PreparedStatement.java:563)<br />
at org.eclipse.birt.data.engine.executor.DataSourceQuery.execute(DataSourceQuery.java:923)<br />
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery$OdaDSQueryExecutor.executeOdiQuery(PreparedOdaDSQuery.java:441)<br />
at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1103)<br />
at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:232)<br />
at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:173)<br />
at org.eclipse.birt.report.engine.data.dte.QueryResultSet.<init>(QueryResultSet.java:98)<br />
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:168)<br />
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:265)<br />
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1890)<br />
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)<br />
at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)<br />
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)<br />
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)<br />
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)<br />
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)<br />
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)<br />
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:99)<br />
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:180)<br />
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.createReport(ReportLauncher.java:594)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.renderReport(ReportLauncher.java:541)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.run(ReportLauncher.java:455)<br />
at org.eclipse.birt.report.debug.internal.core.launcher.ReportLauncher.main(ReportLauncher.java:104)<br />
at org.eclipse.birt.report.debug.internal.core.ReportDebugger.start(ReportDebugger.java:39)<br />
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)<br />
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)<br />
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)<br />
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)<br />
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)<br />
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br />
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br />
at java.lang.reflect.Method.invoke(Unknown Source)<br />
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)<br />
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)<br />
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)<br />
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)<br />
Caused by: java.sql.SQLException: ORA-00933: SQL command not properly ended<br />
<br />
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)<br />
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)<br />
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:590)<br />
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1973)<br />
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1119)<br />
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2191)<br />
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2064)<br />
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2989)<br />
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:658)<br />
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:584)<br />
at org.eclipse.birt.report.data.oda.jdbc.Statement.executeQuery(Statement.java:467)<br />
... 46 more<br />
16-Jun-2011 21:11:20 org.eclipse.birt.report.debug.internal.core.vm.ReportVMServer$1 run<br />
WARNING: [Server] client disconnected
mwilliams
The only thing I can find looking online is the same thing suggested earlier, having the statements separated by a semi-colon. Maybe have a semi-colon at the end as well.
Or maybe Name and Email need to be 'Name' and 'Email'.
ossvisor
i tried almost all possible combination of putting ";" in the query bit no luck ,,,
is there any other way apart from "this.queryText" we can send two sql query
and surprisingly same report work fine with MSQL
alex520
maybe you can try to use procedure as data source ,but base on your sql , you can use two dataset and using a union dataset to join them
ossvisor
tried to apply the same report on classic car model sample database ,, but no luck ....attaching the report
RobR
Unlike MS SQL Server, Oracle does not support multiple SQL Statments in a prepared statement.
I think you would need to run the insert seperately. Not sure exactly how you would do that...but you would need to create your own Statement and run it.
ossvisor
@Rob
thanks Rob ,,,
that explains why this report works in MSQL and not in oracle
but that still left in the same stuck situation ,,
@forum
any clue how to workaround with this issue
RobR
Since no one has jumped in...
Can you create an Oracle Stored Procedure that does an Insert and a Select?
Something like this person did:
http://www.birt-exchange.org/org/forum/index.php/topic/21636-executing-a-stored-procedure-using-javascript-or-java-event-handler/
ossvisor
thanks rob .... I would go with the procedure only as a last resort ...
I will wait some time (before i start working on the procedures ) and hope if someone comes up with some sort of workaround to this issue ....