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
Jason
Please paste you SQL file here. These is no way one should overwrite another.
Eric
Similar Messages
-
How to export the result from executing sql statement to excel file ?
HI all,
Great with Oracle SQL Developer, but I have have a trouble as follwing :
I want to export the result from executing sql statement to excel file . I do easily like that in TOAD ,
anyone can help me to do that ? Thanks so much
SigmasvnHello Sue,
I just tried to export to excel with the esdev extension and got java.lang.NumberFormatException. I found the workaround at Re: Windows Multi-language env, - how do I set English for application lang?
open the file sqldeveloper\jdev\bin\sqldeveloper.conf and add the following two lines:
AddVMOption -Duser.language=en
AddVMOption -Duser.country=USyet now my date formats in excel are 'american-style' instead of german. For example 01-DEC-01 so excel does not recognize it as date and therefore I can not simply change the format.
When export to excel will be native to 1.1 perhaps someone can have a look at this 'feature'
Regards
Marcus -
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 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 -
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 -
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> -
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. -
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 -
High Database server load from expensive SQL statements
Dear all,
I am facing problem in the production sever there is high Database server load from expensive SQL statements as per EVA report
Buffer Load [%] Disk Load [%] CPU Load [%]
55 69 0
Analysis of DB SQL CACHE
EXPENSIVE SQL STATEMENTS OVERVIEW
Object Name CPU Load [%] I/O Load [%] Elapsed Time [%] Executions Records Processed
BSIS 1 9 0 22 90462
CDEF$ 6 6 0 2131113 2575694
BSAD 1 3 0 21 408576
MKPF 1 32 0 180 3899
ICOL$ 9 1 0 2575694 8703798
OBJ$ 6 1 0 3405254 3400023
COL$ 12 0 0 2138793 22919657
MKPF 1 13 0 75 396
MCHB 7 0 0 366543 41708
Please suggest the step by step to reduce the expensive SQL from these table.
RegardsHi,
In tx code ST05 i have find the following deatails.
Duration |Obj. name |Op. |Recs.|RC |Statement
4 TSP03A REOPEN 0 SELECT WHERE "NAME" = 'LOCL' AND "P" = 'S_CLIENTS' 344 TSP03A FETCH 1 0 42 ZRIN DECLARE 0 SELECT WHERE "MANDT" = :A0 AND "BCQ" = :A1 442 ZRIN PREPARE 0 SELECT WHERE "MANDT" = :A0 AND "BCQ" = :A1 3 ZRIN OPEN 0 SELECT WHERE "MANDT" = '600' AND "BCQ" = 'BCQ'
2,181,565 ZRIN FETCH 4 1403
706,267 DBA_SEGME FETCH 99 0 8,248 DBA_SEGME FETCH 99 0 44,994 DBA_SEGME FETCH 99 0 67,713 DBA_SEGME FETCH 99 0
1,367,923 DBA_SEGME FETCH 99 0
16,735|TADIR |FETCH | 1| 1403| |
5
TADIR
REOPEN
0
SELECT WHERE "PGMID" = 'R3TR' AND "OBJECT" = 'TABL' AND "OBJ_NAME" = 'CME__TEXT'
22,415
TADIR
FETCH
1
1403
4
TADIR
REOPEN
0
SELECT WHERE "PGMID" = 'R3TR' AND "OBJECT" = 'TABL' AND "OBJ_NAME" = 'CME_PATTERN_SIGN'
232
TADIR
FETCH
1
1403
4
TADIR
REOPEN
0
SELECT WHERE "PGMID" = 'R3TR' AND "OBJECT" = 'TABL' AND "OBJ_NAME" = 'CML_ARC_DEADLINE'
19,189
TADIR
FETCH
1
1403
4
TADIR
REOPEN
706,267
DBA_SEGME
FETCH
99
0
|
44,994
DBA_SEGME
FETCH
99
0
67,713
DBA_SEGME
FETCH
99
0
Please suggest how to reduce it.
Regards, -
Import/export data from ms sql 7 to xml file in a particular xpdl format
I'm trying to write java program to import/export data from ms sql 7 to xml file in a particular xpdl format. Can anyone suggest how to do it?
take a glance at what these guys do: http://www.openbusinessengine.org/docs/guide.html
-
Tkprof : 0 user SQL statement in trace file
Hello!
Please explain , what is difference of tkprof-converting of user session trace file and an internal/background process ?
Get I message "0 user SQL statement in trace file" cause this difference?
In my target session I issued :
begin
sys.dbms_system.set_ev(...., .., 10046, 12, '');
end;
begin
sys.dbms_system.set_ev(..., .., 10053, 1, '');
end;
/Thanks and regards,
PavelDid you try to tkprof a 10053 trace ?
That is not going to show anything. 10053 traces are meant to be read as they are. tkprof is there to deal with 10046 traces. -
How could I extract past executed SQL statement from dictionary ?
We use oracle11gR2 on win2008R2.
How could I extract the past executed SQL statement from dictionary ? (Is it possible from V$SQLTEXT or other dictionary table ?)IvicaArsov wrote:
Hi,
You can find executed SQL in V$SQLAREA view (if it's still in memory). If it does'n't exist and you have AWR enabled you can query DBA_HIST_SQLTEXT table, but remember that the statistic information in AWR tables is filtered (1 out of 10).
I.Arsov
As you know when taking snapshot oracle will capture only top sql statements and stored in AWR.
But can you please link(source) dba_hist_sqltext contain only 1 out of 10 filtered data?. In dba_hist_active_sess_history yes it contain 1 out of 10 sampled data. -
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
Maybe you are looking for
-
Can anybody advise me what to do as I am having problems opening raw files on CS4 since I have changed to windows 7. I am using a canon mk 5D.
-
Create materialized View fails with "table or view does not exist"
DB: 10.2.0.4 OS: Win 2003 Hi, Here in my tests, i have 2 databases (A(source) and B(backup)), and i am trying to create an mview in database B to replicate data from one test table from database A, only for test purpose. I'm getting the error "table
-
Interrupt Key Sequence? Is there one?
Hey everyone... a quick question. Sometimes I'll forget to leave the 'abort' button in the menu bar and then I write a bit of code that hangs up somewhere and can't stop it. So I have to kill labview to get out. Is there a key sequence (like 'open-
-
Help installing leopard from external fw dvd
I'm trying to install Leopard on an iMacCore Duo with a broken dvd drive. The hdd has been wiped clean. I've got an external LaCie fw dvd drive hooked up to the iMac. No matter what i do the iMac still gives me the folder with the ?. Holding down the
-
i recorded a very important gig last night, and i was trying to arrange the audio into sections, and i cut a few pieces out, knowing i could just undo and get them back. unfortunately, i saved my piece, with those audio files cut out, and now there g