Splitting multiple (pl/sql)/sql statements
Hi,
I am trying to build a pl/sql editor on my website. Everything works fine for single commands, but the way it is going to be used the user can enter multiple commands/blocks on the text editor to execute and in which case the OracleCommand throws an error. I know I can wrap the multiple commands in a block but when I do an ExecuteNonQuery it returns -1 instead of how many rows are changed. For example, the following commands could be entered:
INSERT INTO someTable(col1, col2, col3) VALUES (val1, val2, val3);
INSERT INTO someTable(col1, col2, col3) VALUES (val4, val5, val6);
BEGIN
do something;
END;
And when the user clicks run I have two choices that I know of. I could wrap all the text in BEGIN and END; but as stated above it then does not return the correct row count, or I could try and split up the commands/blocks, which looks like thats what I'm going to have to do. So my question is is there an easy way, or hard anyway, to split multiple statements into individual statements? What is really giving me the problems are the annonymous blocks, so if there is an easy what to tell when an annonymous block is complete that would be very helpful.
Thanks in advance
>
I am trying to build a pl/sql editor on my website. Everything works fine for single commands, but the way it is going to be used the user can enter multiple commands/blocks on the text editor to execute and in which case the OracleCommand throws an error. I know I can wrap the multiple commands in a block but when I do an ExecuteNonQuery it returns -1 instead of how many rows are changed.
>
So far everything you have said is correct. Sounds like things are working exactly as they are documented to work.
Per the Oracle Data Provider for .NET Developer's Guide
http://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleCommandClass.htm
>
OracleCommand Class
An OracleCommand object represents a SQL command, a stored procedure, or a table name. The OracleCommand object is responsible for formulating the request and passing it to the database. If results are returned, OracleCommand is responsible for returning results as an OracleDataReader, a .NET XmlReader, a .NET Stream, a scalar value, or as output parameters.
>
Note the 'a SQL command, a stored procedure, or a table name'. Multiple commands/blocks don't fall into any of those categories so, of course, you get an error.
And in the same document page
>
ExecuteNonQuery returns the number of rows affected, for the following:
•If the command is UPDATE, INSERT, or DELETE and the XmlCommandType property is set to OracleXmlCommandType.None.
•If the XmlCommandType property is set to OracleXmlCommandType.Insert, OracleXmlCommandType.Update, OracleXmlCommandType.Delete.
For all other types of statements, the return value is -1.
>
Your 'block' is not an UPDATE, INSERT or DELETE, etc so, as the doc says, 'For all other types of statements, the return value is -1.
It is YOUR responsibility to submit the individual statements and capture the results of each one.
Similar Messages
-
Iterating through the result of a multiple row sql statement
Hi all,
I would like to access the results of a multiple row sql-statement. However I can't find out how to do this, can you help me here?
I have tried using the "node-set" functions in xpath, but I can't seem to get it right.
How should I approach this scenario?
Sincerely
KimThe jdbc service has the option of returning xml back to you ...if you do it this way then you can interogate the xml
-
Multiple Oracle SQL statements in one Add Command
I am creating a report that needs a bunch of processing(SQL DDL statements) before the final select statement is generated for the report.
I am connecting to Oracle database however Crystal Report only allows me to give one SQL statement in one Add Command.
Is there a way to give multiple statements in one "Add Command" for the report ?
Thanks.you can add more than one "Add Command" in the same report, and you can also treat them as views or table, so you can link them to each others and so on
good luck -
Multiplication in SQL statement
Could somebody help me with the following problem?
I am using a query inside a formatted search to multiply 2 UDF's into the field of the formatted search. (UDF1 * UDF2 = target field).
All fields are defined with 4 decimal positions, but some calculations give strange results: 0,2 * 0,2 = 4 or 2 * 2,2222 = 4,4400. The problems seems to be related to the fact that the target has never more then 2 decimal places.
The UDF's are of type UNIT&TOTALS with structure QUANTITY, the target field is RDR1_QUANTITY. In general settings the number of decimal places is set to 4.
The query is:
SELECT aantal = CAST (( ( CAST ($[$38.U_Inhoud.0] AS Float(8,4) )) *
( CAST ($[$38.U_Aantal_V.0] AS Float(8,4) )) ) AS Float (8,4) )
Has anybody a got idea? I have already tried with and without CAST and FLOAT but the above version is best one sofar. Thanks for your reactions, EgbertTry the following:-
SELECT CAST(ROUND (($[$38.U_Inhoud.NUMBER] * $[$38.U_Aantal.NUMBER]),4) AS VARCHAR(13))
I think the reason you are only ever getting 2 decimal places back is that business one formats the returned numeric result based on the settings for a field of type 'Amount'. You possibly have 'Amounts' set to display 2 decimal places.
The simple workaround I have used for this is to return the field as a character datatype as this will prevent business one from reformatting it.
Also note that you do not need to cast/convert the values you are reading from the screen. By using '.NUMBER' instead of '.0' the values will be processed as numerics rather than as strings.
Hope this helps,
John. -
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 -
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 -
USING MULTIPLE SELECT VARIABLE IN A SQL STATEMENT
In HTMLDB, the value of the parameter of a multiple select box is colon delimited(ie P6_Name = Smith:Jones:Burke). Is there an easy way to use this parameter in a SQL statement?
Example
Select *
from names
where
Name=P6_Name
Select *
from names
where
Name IN ('Smith','Jones','Burke')
Thank youThank you for your response! I'm an idiot. It didn't make sense to me because your talking about a <i>multi-select</i> variable and I was thinking about a <i>select-list</i> variable. My problem is that I need to assign a list of values to one select list item.
<br>
For example:
<br>
SELECT * FROM EMPLOYEE
WHERE EMPLOYEE_TYPE IN ( :SELECT_LIST_RETURN_VALUE );
<br><br>
With the select list as
<br><br>
Display value = All Types, Some Types, One Specific Type<br>
Return Value = (Type1, type2, type3), (type1, type2), (type3)
<br><br>
I've just started in all of this so I'd imagine that I'm probably going about it wrong. -
Multiple Executions Plans for the same SQL statement
Dear experts,
awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.
Below is the awrsqrpt's output for your reference.
WORKLOAD REPOSITORY SQL Report
Snapshot Period Summary
DB Name DB Id Instance Inst Num Release RAC Host
TESTDB 2157605839 TESTDB1 1 10.2.0.3.0 YES testhost1
Snap Id Snap Time Sessions Curs/Sess
Begin Snap: 32541 11-Oct-08 21:00:13 248 141.1
End Snap: 32542 11-Oct-08 21:15:06 245 143.4
Elapsed: 14.88 (mins)
DB Time: 12.18 (mins)
SQL Summary DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
Elapsed
SQL Id Time (ms)
51szt7b736bmg 25,131
Module: SQL*Plus
UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(ACCT_DR_BAL,
0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND TEST_ACC_NB = ACCT_ACC_NB(+)) WHERE
TEST_BATCH_DT = (:B1 )
SQL ID: 51szt7b736bmg DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> 1st Capture and Last Capture Snap IDs
refer to Snapshot IDs witin the snapshot range
-> UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(AC...
Plan Hash Total Elapsed 1st Capture Last Capture
# Value Time(ms) Executions Snap ID Snap ID
1 2960830398 25,131 1 32542 32542
2 3834848140 0 0 32542 32542
Plan 1(PHV: 2960830398)
Plan Statistics DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 25,131 25,130.7 3.4
CPU Time (ms) 23,270 23,270.2 3.9
Executions 1 N/A N/A
Buffer Gets 2,626,166 2,626,166.0 14.6
Disk Reads 305 305.0 0.3
Parse Calls 1 1.0 0.0
Rows 371,735 371,735.0 N/A
User I/O Wait Time (ms) 564 N/A N/A
Cluster Wait Time (ms) 0 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 0 N/A N/A
Invalidations 0 N/A N/A
Version Count 2 N/A N/A
Sharable Mem(KB) 26 N/A N/A
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | | | 1110 (100)| |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS FULL | TEST | 116K| 2740K| 1110 (2)| 00:00:14 |
| 3 | TABLE ACCESS BY INDEX ROWID| ACCT | 1 | 26 | 5 (0)| 00:00:01 |
| 4 | INDEX RANGE SCAN | ACCT_DT_ACC_IDX | 1 | | 4 (0)| 00:00:01 |
Plan 2(PHV: 3834848140)
Plan Statistics DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 0 N/A 0.0
CPU Time (ms) 0 N/A 0.0
Executions 0 N/A N/A
Buffer Gets 0 N/A 0.0
Disk Reads 0 N/A 0.0
Parse Calls 0 N/A 0.0
Rows 0 N/A N/A
User I/O Wait Time (ms) 0 N/A N/A
Cluster Wait Time (ms) 0 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 0 N/A N/A
Invalidations 0 N/A N/A
Version Count 2 N/A N/A
Sharable Mem(KB) 26 N/A N/A
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | | | 2 (100)| |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 28 | 2 (0)| 00:00:01 |
| 3 | INDEX RANGE SCAN | TEST_DT_IND | 1 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| ACCT | 1 | 26 | 4 (0)| 00:00:01 |
| 5 | INDEX RANGE SCAN | INDX_ACCT_DT | 1 | | 3 (0)| 00:00:01 |
Full SQL Text
SQL ID SQL Text
51szt7b736bm UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL, 0) +
NVL(ACCT_DR_BAL, 0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND PB
RN_ACC_NB = ACCT_ACC_NB(+)) WHERE TEST_BATCH_DT = (:B1 )Your input is highly appreciated.
Thanks for taking your time in answering my question.
RegardsOracle Lover3 wrote:
Dear experts,
awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.If you're using bind variables and you've histograms on your columns which can be created by default in 10g due to the "SIZE AUTO" default "method_opt" parameter of DBMS_STATS.GATHER__STATS it is quite normal that you get different execution plans for the same SQL statement. Depending on the values passed when the statement is hard parsed (this feature is called "bind variable peeking" and enabled by default since 9i) an execution plan is determined and re-used for all further executions of the same "shared" SQL statement.
If now your statement ages out of the shared pool or is invalidated due to some DDL or statistics gathering activity it will be re-parsed and again the values passed in that particular moment will determine the execution plan. If you have skewed data distribution and a histogram in place that reflects that skewness you might get different execution plans depending on the actual values used.
Since this "flip-flop" behaviour can sometimes be counter-productive if you're unlucky and the values used to hard parse the statement leading to a plan that is unsuitable for the majority of values used afterwards, 11g introduced the "adaptive" cursor sharing that attempts to detect such a situation and can automatically re-evaluate the execution plan of the statement.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
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!!! -
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 -
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] -
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> -
Workspace to parse SQL statements from multiple database schema's
Hi ,
When go through the following link of workspace admin user :
Home>HTML DB Workspace Administration>Manage Services>Schema Reports>Workspace Schemas there I saw "Your workspace has the privilege to parse SQL statements using the following database schemas. Note that the terms database schema and database user can be used interchangeably.
" at the right pane.
So how can i make my workspace to parse SQL statements from multiple database schema's ?That must be listed there .But i have only one schema in view ? Can i make it multiple ?If then How ?
Anybody have an idea ?
ROSYAssign as many schemas to your workspace as you want using the administration app. Read about it in the doc.
Scott -
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 -
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.
Maybe you are looking for
-
Combining color and black-and-white pages in a single pdf
I have a document in which I have a few images with colors. The document needs to be printed but currently the whole document is in color so the costs are expensive. I want to convert the pages without the images to black-and-white and keep the color
-
"Volume Full" Message when building DVD in CS3
Ok. I'm using Encore CS3. I'm authoring a Graduation DVD for a local college. The project includes 6 menus (Main, and 5 Submenus) and 1hour 45mins of Video. The video has all been transcoded and automatically compressed so that there is 19 MB free on
-
If you download individual episodes of a tv series and then decide to get the whole season, is there a way to get credited for the individual episodes already purchased? Does iTunes store recognize the past purchases if there is a credit?
-
Electrical Engineer with automated test experience looking for job in San Antonio Area
I am an Electrical Engineer with 33 years of experience. Much of my experience involves computer programming with an emphasis on electrical systems, either controlling equipment or automated testing. I have experience in numerous languages, most rece
-
Creating string array constant
Hey, this is probably a stupid question but I am still trying to figure out everything in LabVIEW. Is there a way to create an array constant that holds strings? I know you can define an numerical array constant but can you also do one for strings, o