Oracle

preserve leading blanks in Sqlplus

Just when you thought life became easier with emerging technologies in 2003 you come across these little bugging problems of SQL*Plus, the worst developer tool on earth…

Leading blanks are stripped by default when you do an DBMS_OUTPUT.Put_Line – not the trailing of course – those are more important in code-generators – they make the files really big (assuming a LINESIZE of 200).

Well, fortunately there's a way to fix the output of the following sample:

this is the script test.sql:

</p>

	<p><span class="caps">BEGIN</span></p>

	<p>  dbms_output.put_line('    <span class="caps">TEST</span> with 4 spaces');</p>

	<p>  dbms_output.put_line('      <span class="caps">TEST</span> with 2 tabs');</p>

	<p>END;</p>

	<p>/</p>

	<p>

Quote:

SQL> SET SERVEROUT ON size 1000000

SQL> @test

TEST with 4 spaces

        TEST with 2 tabs

use the format wrap to avoid trimming the leading blanks and you are done :-)

Quote:

SQL> SET SERVEROUT ON size 1000000 format wrap

SQL> @test

    TEST with 4 spaces

        TEST with 2 tabs

Explanation:

Only the default WORD_WRAPPED causes the trim to occur. The other options WRAPPED and TRUNACTED don't trim and hence don't suppress blank output (or leading spaces).

When generating code in general I use the following sqlplus settings:

</p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">NEWPAGE</span>      0</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">SPACE</span>        4</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">PAGESIZE</span>     0</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">TERMOUT</span>     ON</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">FEEDBACK</span>   OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">HEADING</span>    OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">VERIFY</span>     OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">TIME</span>       OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">TIMING</span>     OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">ECHO</span>       OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">PAUSE</span>      OFF</span></p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">RECSEPCHAR</span> </span>' '</p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">SERVEROUT</span> ON</span> size 1000000 format wrap                               </p>

	<p><span class="caps">SET</span> <span class="caps"><span class="caps">LINESIZE</span>   200</span></p>

	<p>

Average rating
(0 votes)

Comments

preserve leading blanks in Sqlplus

What about setting TRIM and TRIMSPOOL to remove
trailing blanks?

Similar entries

  • Texas Instruments introduces first 1394b products…. The availability of IEEE 1394b devices enables much greater distances and higher performance for home networking and entertainment applications such as whole house video and audio. The plug-and-play, quality of service and other ease-of-use…

  • It's hard to imagine that anyone with an inkjet printer hasn't at some time had their printer run out of ink, only to find themselves without a replacement ink cartridge. Whether you just use your computer at home for pleasure or as part of your business this can be a really frustrating experience. At best not having a replacement ink cartridge might mean you can't print some information off the internet; or at worse if you're a business user you might not be able to process a letter to clinch a business opportunity. You now also have to spend not only money but your precious time shopping around to get your replacement ink cartridges. The convenient way to get replacement ink cartridges today is, of course, to do it online.

  • MyDoom detecting support

  • Found this nice tool today for estimating the PageRank value without the IE toolbar (well I would love to use Opera or Mozilla for this thing aswell… but Google doesn't really care about us…) I still have to validate this…

  • PeopleSoft Chief: No Way, Oracle Craig Conway, chief executive of PeopleSoft says Oracle cannot make an offer for the company that would fly with shareholders. PeopleSoft’s response to competitor Oracle’s bid to take over the company compares Larry Ellison to…