Operating System - OpenVMS
1753440 Members
4692 Online
108794 Solutions
New Discussion юеВ

Re: SQL Select on ORACLE

 
SOLVED
Go to solution
smsc_1
Regular Advisor

SQL Select on ORACLE


Hello all,
Hope I can ask in this room.
I'm driving crazy with the following SQL problem.

I would like to perform a simple select with many fields like:

SQL> select field1,field2,field3,field4, from table;

Since this is only an example (normally I need at least 20 fields), I would like to separate the result with a symbol like .,- (not matter witch symbol).
This because for me will be much simple to export on excell.

Is there a way to separate the result with a symbol?

This is what I have on OpenVMS 8.3.1H1
SQL> sho ver
Current version of SQL is: Oracle Rdb SQL V7.2-100
Underlying versions are:
Database with filename DB_log
Oracle Rdb V7.2-100
Rdb/Dispatch V7.2-100 (OpenVMS IA64)

Regards
Luca
./ Lucas
6 REPLIES 6
Duncan Morris
Honored Contributor

Re: SQL Select on ORACLE

Hi Luca,

have you tried

select field1 || ',' || field2 || ',' || field3 from table;

Regards,

Duncan
Hein van den Heuvel
Honored Contributor

Re: SQL Select on ORACLE

Under SQLplus you can use SET COLSEP but that's not available in RDB SQL best I can tell.

And while using for example "SET COLSEP ," is a convenient way to quickly generate a CSV file, it is rarely adequate. Notably folks typically want trimmed spaces and double quoted strings to protect against commas within the columns.

So the typical solution often becomes the manual concatenation with a seperator as Duncan outlines.
You may need a PRINT to get a proper header line.

I suppose you could also play with the EDIT_STRING clause on columns in a view to use ',XXXX'. That'd be tedious.


Personally I'd look into postprocessing the standard fixed-column output with a tool like TPU or PERL for format it just the way I'd like it. It is tedious again and worse, it spreads the knowledge of the query and columns across multiple files, so they could get out of sync.
Perl has several module to help read/write CSV files. For example:
http://search.cpan.org/~tilly/Text-xSV-0.21/lib/Text/xSV.pm

fwiw,
Hein.


smsc_1
Regular Advisor

Re: SQL Select on ORACLE


Thanks all,
but if I use:

select field1 || ',' || field2 || ',' || field3 from table;

I got as error:

%SQL-F-UNSNUMXPR, Unsupported numeric expression

What does it mean??
./ Lucas
Wim Van den Wyngaert
Honored Contributor
Solution

Re: SQL Select on ORACLE

Try
select field1, "||" , field2 , "||" ...

Wim
Wim
smsc_1
Regular Advisor

Re: SQL Select on ORACLE


select field1, "||" , field2 , "||" ...

Is the solution.... Thanks to all!!!


./ Lucas
smsc_1
Regular Advisor

Re: SQL Select on ORACLE


Closing Thread and assign points!
./ Lucas