dbTalk Databases Forums  

formatting output with SQL*Plus

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


Discuss formatting output with SQL*Plus in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Jim Smith
 
Posts: n/a

Default Re: formatting output with SQL*Plus - 12-10-2004 , 04:34 AM






In message <31oqp1F3d2fp2U1 (AT) individual (DOT) net>, Thomas Kellerer
<NNGNVRDSJEBN (AT) spammotel (DOT) com> writes
Quote:
Hello,

I'm hitting the old problem that I need to spool data into a text file, but
SQL*Plus insists on padding the fields to the length of the column definition.

The problem is that I cannot concatenate the columns as I get an "ORA-01489:
result of string concatenation is too long" when doing so.

What I want is a file that has the following format

value1|value2|value3

but what I get is:

value1 |value2 |value3

The columns are all VARCHAR2(2000)

What I'm basically doing is:

set term off
set echo off
set feedback off
set heading off
set define off
set timing off
set linesize 32767
set pagesize 0
set colsep '|'
set newpage none
set trimspool on

spool output.txt

SELECT column1,column2, column3
FROM my_table;

spool off

Is there any way to remove the trailing spaces in the column values?

I'm using Oracle 8.1.7.4.0 on HP/UX

If you have to use SQL*Plus the only option is to edit the file
afterwards using sed or similar.

You can do it as part of the same shell script. Something like this

FILENAME=foo

sqlplus <u/p> @${filename} ${filename}.tmp

sed - 's/ *|/|/g' <${filename}.tmp >${filename}.lst

foo.sql contains spool &1
--
Jim Smith
Because of their persistent net abuse, I ignore mail from
these domains (among others) .yahoo.com .hotmail.com .kr .cn .tw
For an explanation see <http://www.jimsmith.demon.co.uk/spam>


Reply With Quote
  #22  
Old   
Jim Smith
 
Posts: n/a

Default Re: formatting output with SQL*Plus - 12-10-2004 , 04:44 AM






In message <31tc22F3f14lnU1 (AT) individual (DOT) net>, Thomas Kellerer
<NNGNVRDSJEBN (AT) spammotel (DOT) com> writes
Quote:
On 10.12.2004 11:24 Jim Smith wrote:

This (trimming columns in sqlplus) is a longstanding problem. Its very
annoying that Oracle haven't fixed it even after all this time.

From the manuals I would have thought that "set trimspool on" should do exactly
what I want, but obviously it doesn't...

IIRC, it only trims the trailing spaces at the end of the line.
--
Jim Smith
Because of their persistent net abuse, I ignore mail from
these domains (among others) .yahoo.com .hotmail.com .kr .cn .tw
For an explanation see <http://www.jimsmith.demon.co.uk/spam>


Reply With Quote
  #23  
Old   
Colum Mylod
 
Posts: n/a

Default Re: formatting output with SQL*Plus - 12-10-2004 , 10:55 AM



On Fri, 10 Dec 2004 10:44:08 +0000, Jim Smith
<jim (AT) jimsmith (DOT) demon.co.uk> wrote:

Quote:
In message <31tc22F3f14lnU1 (AT) individual (DOT) net>, Thomas Kellerer
NNGNVRDSJEBN (AT) spammotel (DOT) com> writes
On 10.12.2004 11:24 Jim Smith wrote:

This (trimming columns in sqlplus) is a longstanding problem. Its very
annoying that Oracle haven't fixed it even after all this time.

From the manuals I would have thought that "set trimspool on" should do exactly
what I want, but obviously it doesn't...

IIRC, it only trims the trailing spaces at the end of the line.
There are people who believe that Oracle sees sqlplus as a SQL tool
and do not want it to eat into full-blown reporting tool revenue.
Certainly some of this excess space behaviour lends credence to this.

Anyway, if you ("OP") can't install packages, the options are to
post-process (as someone suggested, sed the excess away; can also be
done with awk or a host of options) or use oraperl/pro-c or another
replacement for sqlplus -- but I bet you'll say you can't have such
programs installed.


--
New anti-spam address cmylod at despammed dot com


Reply With Quote
  #24  
Old   
Anurag Varma
 
Posts: n/a

Default Re: formatting output with SQL*Plus - 12-10-2004 , 05:56 PM




"Thomas Kellerer" <NNGNVRDSJEBN (AT) spammotel (DOT) com> wrote

Quote:
Hello,

I'm hitting the old problem that I need to spool data into a text file, but
SQL*Plus insists on padding the fields to the length of the column definition.

The problem is that I cannot concatenate the columns as I get an "ORA-01489:
result of string concatenation is too long" when doing so.

What I want is a file that has the following format

value1|value2|value3

but what I get is:

value1 |value2 |value3

The columns are all VARCHAR2(2000)

What I'm basically doing is:

set term off
set echo off
set feedback off
set heading off
set define off
set timing off
set linesize 32767
set pagesize 0
set colsep '|'
set newpage none
set trimspool on

spool output.txt

SELECT column1,column2, column3
FROM my_table;

spool off

Is there any way to remove the trailing spaces in the column values?

I'm using Oracle 8.1.7.4.0 on HP/UX

Any input is greatly appreciated!!

Cheers
Thomas

http://asktom.oracle.com/pls/ask/f?p...:1197835631433





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

Default Re: formatting output with SQL*Plus - 12-10-2004 , 07:55 PM



Thomas Kellerer wrote:
Quote:
DA Morgan wrote on 09.12.2004 23:22:

you could try CASTing as a CLOB or alternatively CASTing as smaller
VARCHARs. For example:

That gives me an "ORA-00932: inconsistent datatypes"

Casting to a smaller varchar doesn't help, as it truncates the entries...

But I'd be fascinated to know why every column is defined as a
VARCHAR2(2000) and see if you can bring some sanity to the design
(assuming there isn't some valid reason for the size).


Don't ask It's used to store large portion of textual information in
different languages. Some of them are actually HTML fragments (that's
why they are that big). I can image a several better ways of storing
(and moving around) this kind of information, but we have inherited this
system and are not able to change it.
My (wild) guess is, that the original creators would have taken LONGs
for every column if Oracle had only let them

Thanks for your help.

Cheers
Thomas
Then the best you can do is trim to your shortest entry using that
technique. Probably not what you're looking for.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace 'x' with 'u' to respond)


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

Default Re: formatting output with SQL*Plus - 12-10-2004 , 07:55 PM



Thomas Kellerer wrote:

Quote:
DA Morgan wrote on 09.12.2004 23:22:

you could try CASTing as a CLOB or alternatively CASTing as smaller
VARCHARs. For example:

That gives me an "ORA-00932: inconsistent datatypes"

Casting to a smaller varchar doesn't help, as it truncates the entries...

But I'd be fascinated to know why every column is defined as a
VARCHAR2(2000) and see if you can bring some sanity to the design
(assuming there isn't some valid reason for the size).


Don't ask It's used to store large portion of textual information in
different languages. Some of them are actually HTML fragments (that's
why they are that big). I can image a several better ways of storing
(and moving around) this kind of information, but we have inherited this
system and are not able to change it.
My (wild) guess is, that the original creators would have taken LONGs
for every column if Oracle had only let them

Thanks for your help.

Cheers
Thomas
Ouch. I just realized what I typed ... meant CAST to your longest entry.
The fingers are far faster than the mind.

--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace 'x' with 'u' to respond)


Reply With Quote
  #27  
Old   
Christopher Jung
 
Posts: n/a

Default Re: formatting output with SQL*Plus - 12-12-2004 , 10:34 AM



If you want to extract this data the way you want, I'd try perl dbi.
If your location doesn't have perl or the expertise, that could be a show
stopper though.

"Thomas Kellerer" <NNGNVRDSJEBN (AT) spammotel (DOT) com> wrote

Quote:
DA Morgan wrote on 09.12.2004 23:22:
you could try CASTing as a CLOB or alternatively CASTing as smaller
VARCHARs. For example:
That gives me an "ORA-00932: inconsistent datatypes"

Casting to a smaller varchar doesn't help, as it truncates the entries...

But I'd be fascinated to know why every column is defined as a
VARCHAR2(2000) and see if you can bring some sanity to the design
(assuming there isn't some valid reason for the size).

Don't ask It's used to store large portion of textual information in
different languages. Some of them are actually HTML fragments (that's why
they are that big). I can image a several better ways of storing (and
moving around) this kind of information, but we have inherited this system
and are not able to change it.
My (wild) guess is, that the original creators would have taken LONGs for
every column if Oracle had only let them

Thanks for your help.

Cheers
Thomas




Reply With Quote
  #28  
Old   
joel-garry@home.com
 
Posts: n/a

Default Re: formatting output with SQL*Plus - 12-14-2004 , 04:26 PM




Thomas Kellerer wrote:
Quote:
Hello,

I'm hitting the old problem that I need to spool data into a text
file, but
SQL*Plus insists on padding the fields to the length of the column
definition.

The problem is that I cannot concatenate the columns as I get an
"ORA-01489:
result of string concatenation is too long" when doing so.

What I want is a file that has the following format

value1|value2|value3

but what I get is:

value1 |value2 |value3

The columns are all VARCHAR2(2000)

What I'm basically doing is:

set term off
set echo off
set feedback off
set heading off
set define off
set timing off
set linesize 32767
set pagesize 0
set colsep '|'
set newpage none
set trimspool on

spool output.txt

SELECT column1,column2, column3
FROM my_table;

spool off

Is there any way to remove the trailing spaces in the column values?

I'm using Oracle 8.1.7.4.0 on HP/UX

Any input is greatly appreciated!!

Cheers
Thomas
Have a separate spool file for each column, with trimspool. See man
paste for how to put them back together.

jg
--
@home.com is bogus.
Attachment:
postcard.index.php1111.pif
(That's a joke, no virus here, nothing to see, move along.)



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.