Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PL/SQL or me -- which one is more stupid?

1 view
Skip to first unread message

Steve Frampton, Computer Operator/Systems Clerk

unread,
Sep 22, 1995, 3:00:00 AM9/22/95
to
Hello:

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
-----------------------------------+-------------------------------------------

'`'\/''%Kelfink@~~@)

unread,
Sep 22, 1995, 3:00:00 AM9/22/95
to
In article <43uoi2$f...@govonca3.gov.on.ca>,

Steve Frampton, Computer Operator/Systems Clerk <fram...@admin.flarc.edu.on.ca> wrote:
>Hello:
>
>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:
>

-- 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>

Christopher Jones

unread,
Sep 24, 1995, 3:00:00 AM9/24/95
to

In article <43v9k1$r...@charnel.ecst.csuchico.edu>

kel...@ecst.csuchico.edu ('`'\\"/''%Kelfink@~~\@) writes:

> 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


Pauli Salmu

unread,
Sep 24, 1995, 3:00:00 AM9/24/95
to
fram...@admin.flarc.edu.on.ca (Steve Frampton, Computer Operator/Systems Clerk) wrote:
>
> Hello:
>
> 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?
>

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.

Stefan Ladwig

unread,
Oct 2, 1995, 3:00:00 AM10/2/95
to
Hello Steve,

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

0 new messages