If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How do I print space in the beginning of a line

Here I tried to output some space key in the beginning of a line. However, SQL Plus seems to ignore those space keys. If I add something like '--' before the space keys, it works. Is there a way to print space key before other characters?

Test:

SQL> exec dbms_output.put_line(' there are space in the beginning of the line.') ;
there are space in the beginning of the line.

PL/SQL procedure successfully completed.

SQL> exec dbms_output.put_line('-- there are space in the beginning of the line.') ;
-- there are space in the beginning of the line.

Why cannot I simply use ' ' to output a space key? I thought this is just the issue of SQL Plus setting. I know you can get rid of the trailing space by "set trim on". Any idea about preserving the leading space? Thanks!

Because you simply cannot use '' to output a space. You have two options: using chr(x) or string single quotation marks together in the proper manner to produce the desired effect. If you have access to MetaLink, read this article: Note:1005607.6
Subject: HOW TO EMBED SINGLE QUOTE IN STRING

Originally posted by dba_admin Why cannot I simply use ' ' to output a space key? I thought this is just the issue of SQL Plus setting.

You thought correctly. No need to use warious CHR() and simmilar tricks to suppres SQL*Plus from trimming the leading spaces with DBMS_OUTPUT. Just read te SQL*Plus manual about the options about SET SERVEROUTPUT FORMAT setting. Example:

Code:

SQL> set serveroutput on
SQL> exec dbms_output.put_line(' There should be leading spaces.')
There should be leading spaces.
PL/SQL procedure successfully completed.
SQL> set serveroutput on format
Usage: SET SERVEROUTPUT { ON | OFF } [SIZE n]
[ FOR[MAT] { WRA[PPED] | WOR[D_WRAPPED] | TRU[NCATED] } ]
SQL> set serveroutput on format wrapped
SQL> exec dbms_output.put_line(' There should be leading spaces.')
There should be leading spaces.
PL/SQL procedure successfully completed.
SQL>

Jurij ModicASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?