Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle trimspool only trailing blanks (not leading blanks)

Tags:

oracle

sqlplus

I am wondering if there's any tricks to get trimspool to only trim trailing whitespace on the right.

I have code that uses dbms_output.put_line to print to the console, and the output often has indentation to make it easier to scan with the eyes. I set the line width rather large to make some of the output easier to read, so I also set trimspool to get rid of extra white space. The only problem is that now the leading which space is removed as well as the trailing whitespace. Is there a way to fix this? I could add a leading (before the leading whitespace) "." character to some of the output statements, but I'm not allowed to modify the code in most of the packages.


Here's what it outputs with no trimmimg:

 level 1                          (EOL)
     level 2                      (EOL)
       Some data                  (EOL)

Here's what it currently outputs with trimspool on:

level 1(EOL)
level 2(EOL)
Some data(EOL)

HEre's what I want:

 level 1(EOL)
     level 2(EOL)
       Some data(EOL)
like image 902
FrustratedWithFormsDesigner Avatar asked Jan 21 '11 16:01

FrustratedWithFormsDesigner


People also ask

How to remove trailing space in spooling Oracle?

The Oracle documentation says this about removing trailing spaces with "set trimspool" or "set trimout" commands: SET TRIMOUT ON or SET TRIMSPOOL ON removes trailing blanks at the end of each displayed or spooled line. Setting these variables ON can reduce the amount of data written.

How to remove trailing spaces from a column in Oracle?

The Oracle TRIM function is used to remove all leading or trailing characters (or both) from a character string. If trim_character or trim_source is a character literal, then it is necessary to enclose it in single quotation marks. When no trim_character is specified, then the default value is a blank space.

What is Trimspool in Sqlplus?

The TRIMSPOOL setting controls whether SQL*Plus writes trailing spaces when spooling data to a file. The default setting is OFF, which causes SQL*Plus to write each line to the spool file in its entirety, trailing spaces and all.

What is set Headsep off?

SET HEADS[EP] Is the command, which may be abbreviated SET HEADS. heading_separator. Is the new heading separator character, which may be used in subsequent COLUMN commands to mark line breaks in multiline column headings.


1 Answers

I guess you're after

set serveroutput on size 100000 format wrapped

if I do understand your question.

If I do this:

set serveroutput on size 1000000

begin
  dbms_output.put_line('no indent');
  dbms_output.put_line('   indent');
end;
/

SQL*Plus outputs:

no indent
indent

If, however, I do

set serveroutput on size 1000000 format truncated

begin
  dbms_output.put_line('no indent');
  dbms_output.put_line('   indent');
end;
/

SQL*Plus outputs:

no indent
   indent

You have to set trimspool on in order to eliminate the spaces up to eol.

like image 180
René Nyffenegger Avatar answered Sep 16 '22 21:09

René Nyffenegger