dbTalk Databases Forums  

SELECT stmt to file with tab delimiters

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss SELECT stmt to file with tab delimiters in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Occidental
 
Posts: n/a

Default SELECT stmt to file with tab delimiters - 12-05-2007 , 05:18 PM






Suppose you have a SELECT stmt of form:

SELECT Field1, Field2, Field3
FROM Table1
WHERE etc

What would it take to generate a file from the output this stmt, where
the fields are tab-delimited? I'm working with an Oracle guy who
claims it is impossible. In mysql it is easy

SELECT Field1, Field2, Field3
INTO OUTFILE 'filename'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM Table1
WHERE etc

Reply With Quote
  #2  
Old   
DA Morgan
 
Posts: n/a

Default Re: SELECT stmt to file with tab delimiters - 12-05-2007 , 05:56 PM






Occidental wrote:
Quote:
Suppose you have a SELECT stmt of form:

SELECT Field1, Field2, Field3
FROM Table1
WHERE etc

What would it take to generate a file from the output this stmt, where
the fields are tab-delimited? I'm working with an Oracle guy who
claims it is impossible. In mysql it is easy

SELECT Field1, Field2, Field3
INTO OUTFILE 'filename'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM Table1
WHERE etc
SELECT col1 || chr(09) || col2
FROM ....;

PS: They are columns ... not fields.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #3  
Old   
Ed Prochak
 
Posts: n/a

Default Re: SELECT stmt to file with tab delimiters - 12-05-2007 , 10:07 PM



On Dec 5, 6:18 pm, Occidental <Occiden... (AT) comcast (DOT) net> wrote:
Quote:
Suppose you have a SELECT stmt of form:

SELECT Field1, Field2, Field3
FROM Table1
WHERE etc

What would it take to generate a file from the output this stmt, where
the fields are tab-delimited? I'm working with an Oracle guy who
claims it is impossible. In mysql it is easy

SELECT Field1, Field2, Field3
INTO OUTFILE 'filename'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM Table1
WHERE etc
Another solution involves the COLSEP (Column Separator) in SQLPLUS.

Look up the SET command for the COLSEP option.

Ed


Reply With Quote
  #4  
Old   
joel garry
 
Posts: n/a

Default Re: SELECT stmt to file with tab delimiters - 12-07-2007 , 07:05 PM



On Dec 5, 3:56 pm, DA Morgan <damor... (AT) psoug (DOT) org> wrote:
Quote:
Occidental wrote:
Suppose you have a SELECT stmt of form:

SELECT Field1, Field2, Field3
FROM Table1
WHERE etc

What would it take to generate a file from the output this stmt, where
the fields are tab-delimited? I'm working with an Oracle guy who
claims it is impossible. In mysql it is easy

SELECT Field1, Field2, Field3
INTO OUTFILE 'filename'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM Table1
WHERE etc

SELECT col1 || chr(09) || col2
FROM ....;

PS: They are columns ... not fields.
But what if the data has embedded tabs?

jg
--
@home.com is bogus.
Bad DBA! Bad, Bad, Bad DBA! http://www.channelregister.co.uk/200...sumer_records/


Reply With Quote
  #5  
Old   
DA Morgan
 
Posts: n/a

Default Re: SELECT stmt to file with tab delimiters - 12-08-2007 , 12:00 PM



joel garry wrote:
Quote:
On Dec 5, 3:56 pm, DA Morgan <damor... (AT) psoug (DOT) org> wrote:
Occidental wrote:
Suppose you have a SELECT stmt of form:
SELECT Field1, Field2, Field3
FROM Table1
WHERE etc
What would it take to generate a file from the output this stmt, where
the fields are tab-delimited? I'm working with an Oracle guy who
claims it is impossible. In mysql it is easy
SELECT Field1, Field2, Field3
INTO OUTFILE 'filename'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM Table1
WHERE etc
SELECT col1 || chr(09) || col2
FROM ....;

PS: They are columns ... not fields.

But what if the data has embedded tabs?

jg
--
@home.com is bogus.
Bad DBA! Bad, Bad, Bad DBA! http://www.channelregister.co.uk/200...sumer_records/
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> create table t (
2 col1 VARCHAR2(20),
3 col2 VARCHAR2(20));

Table created.

SQL> INSERT INTO t VALUES ('A' || CHR(09) || 'B', 'X' || CHR(09) || 'Y');

1 row created.

SQL> SELECT * FROM t;

COL1 COL2
-------------------- --------------------
A B X Y

SQL> SELECT col1 || CHR(09) || col2
2 FROM t;

COL1||CHR(09)||COL2
-----------------------------------------
A B X Y

SQL>
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #6  
Old   
joel garry
 
Posts: n/a

Default Re: SELECT stmt to file with tab delimiters - 12-10-2007 , 12:14 PM



On Dec 8, 10:00 am, DA Morgan <damor... (AT) psoug (DOT) org> wrote:
Quote:
joel garry wrote:
On Dec 5, 3:56 pm, DA Morgan <damor... (AT) psoug (DOT) org> wrote:
Occidental wrote:
Suppose you have a SELECT stmt of form:
SELECT Field1, Field2, Field3
FROM Table1
WHERE etc
What would it take to generate a file from the output this stmt, where
the fields are tab-delimited? I'm working with an Oracle guy who
claims it is impossible. In mysql it is easy
SELECT Field1, Field2, Field3
INTO OUTFILE 'filename'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM Table1
WHERE etc
SELECT col1 || chr(09) || col2
FROM ....;

PS: They are columns ... not fields.

But what if the data has embedded tabs?

jg
--
@home.com is bogus.
Bad DBA! Bad, Bad, Bad DBA! http://www.channelregister.co.uk/200...s_consumer_rec...

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> create table t (
2 col1 VARCHAR2(20),
3 col2 VARCHAR2(20));

Table created.

SQL> INSERT INTO t VALUES ('A' || CHR(09) || 'B', 'X' || CHR(09) || 'Y');

1 row created.

SQL> SELECT * FROM t;

COL1 COL2
-------------------- --------------------
A B X Y

SQL> SELECT col1 || CHR(09) || col2
2 FROM t;

COL1||CHR(09)||COL2
-----------------------------------------
A B X Y

Now truncate the table, and show the sqlloader command file for
loading that data with embedded tabs in the file into the table.

Since you don't seem to think there is an unhandled problem with
delimiters in the data...

jg
--
@home.com is bogus.
Cartoon of dog peeing wins major journalism award:
http://www.signonsandiego.com/uniont..._1m8breen.html
http://www.signonsandiego.com/news/f...hiveindex.html


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.