amar on web

Aligning output from dbms_output.put_line

dbms_output.put_line removes all the spacing present at the beginning of a line. There are times when we spool output in sql*plus but the alignment is lost. Is there anyway of preserving the white spaces?

      set serveroutput on 
      begin 
         dbms_output.put_line('declare'); 
         dbms_output.put_line('   l_num number(3);'); 
         dbms_output.put_line('begin'); 
         dbms_output.put_line('   select 1'); 
         dbms_output.put_line('   into   l_num'); 
         dbms_output.put_line('   where  ename = ''amar'''); 
         dbms_output.put_line('exception'); 
         dbms_output.put_line('   when others then'); 
         dbms_output.put_line('      message(substr(sqlerrm, 1, 100))'); 
         dbms_output.put_line('end;'); 
      end; 
The above code will provide output ignoring the spacing provided for alignment.

    set serveroutput on size 1000000 format wrapped 
    set serveroutput on size 1000000 format truncated 
The second option will truncate a line exceeding the max line size. The first option will wrap it to the next line. Both options will preserve the leading spaces which help in aligning the output.

One more way of doing it is by use of CHR(9) or CHR(10) as below, though this option may not work across charactersets.
    dbms_output.put_line(chr(9)||'l_num number(3);');
    dbms_output.put_line(chr(10)||'      l_num number(3);'); 

Best viewed in medium text size. Please refresh this page (F5) to view the latest information.
This page was created on 16-dec-2001 and last updated on 16-dec-2001.
please forward all queries to amar_padhi@fastmail.fm