I am writing a calendar-generating application in PL/SQL. I would really
like to know why the following code generates two very different results:
--- begin ---
set serveroutput on;
declare
test varchar2(29);
begin
test:='';
for i in 1..7 loop
test := test||' '||'|'; /* 3 spaces */
end loop;
dbms_output.put_line(test);
test:='';
for i in 1..7 loop
test := test||'***'||'|'; /* 3 stars */
end loop;
dbms_output.put_line(test);
end;
/
set serveroutput off;
--- end ---
And, here is the output:
--- begin ---
| | | | | | |
***|***|***|***|***|***|***|
--- end ---
This all seems pretty silly, to me. Any ideas?
Thanks in advance...
-------------------------------------------------------------------------------
This article contains my own words formed by my own opinions. I speak on my
own behalf and my views do not necessarily agree with those of my employer.
-----------------------------------+-------------------------------------------
Steve Frampton | Phone: (613) 544-4927, extension 331
Computer Operator/Systems Clerk | Fax: (613) 530-4761
Frontenac-Lennox & Addington RCSSB | E-mail: fram...@admin.flarc.edu.on.ca
-----------------------------------+-------------------------------------------
-------------------------------------------------------------------------------
This article contains my own words formed by my own opinions. I speak on my
own behalf and my views do not necessarily agree with those of my employer.
-----------------------------------+-------------------------------------------
Steve Frampton | Phone: (613) 544-4927, extension 331
Computer Operator/Systems Clerk | Fax: (613) 530-4761
Frontenac-Lennox & Addington RCSSB | E-mail: fram...@admin.flarc.edu.on.ca
-----------------------------------+-------------------------------------------
-- code deleted --
>And, here is the output:
>
>--- begin ---
>| | | | | | |
>***|***|***|***|***|***|***|
>--- end ---
>
>This all seems pretty silly, to me. Any ideas?
I got the same results, running your script.
Oracle is left-trimming!
Here's a simplified example:
declare
test varchar2(40);
begin
dbms_output.put_line(' Right justified.');
end
/
Generates output:
Right Justified
Looks like put_line is trimming your output on the left.
I'm not practiced in these routines, but maybe there's an alternate
function, or some other parameter/option to prevent this.
Hope that helps, or at least lets you know you're not crazy.
Kevin Fries
Developer/DBA
e-mail kel...@ecst.csuchico.edu
--
<Insert signature here>
> I got the same results, running your script.
> Oracle is left-trimming!
>
> Here's a simplified example:
>
> declare
> test varchar2(40);
> begin
> dbms_output.put_line(' Right justified.');
> end
> /
> Generates output:
>
> Right Justified
>
> Looks like put_line is trimming your output on the left.
Put_line is OK. SQL*Plus itself does a form of word wrapping when it
displays server output. The left trimming is similar to the age-old
trimming behavior of the COLUMN x WORD_WRAPPED command.
SQL*Plus 3.3 allows you to specify TRUNCATED, WRAPPED or WORD_WRAPPED
(the default) in the SET SERVEROUTPUT command.
Chris
--
Christopher Jones, cjo...@au.oracle.com
It's as simple as it looks: put_line strips leading spaces. You can
use some other blank character in the beginning of the line,
preferably produced with function CHR to make the code readable.
it don't seems silly to me. DBMS_Output.Putline surpresses
Spaces, wich are in front. If you have declared a number-varaible
with a fixed precision, you also see no beginning 0's.
I hope it helps you.
Stefan