Home » SQL & PL/SQL » SQL & PL/SQL » LPAD space filled output (HP-UNIX/Windows XP)
LPAD space filled output [message #314971] Fri, 18 April 2008 07:36 Go to next message
ritvikd
Messages: 11
Registered: January 2007
Junior Member
Hi,
I have PL/SQL block which is using dbms_output.put_line to print a variable v_STR (v_STR length 13 dataype CHAR).
I have used LPAD to Left PAD the string (which is numeric like 43245.67) with spaces. The total lenght should be 18 but what I get from dbms_output.put_line is just the string and no spaces.

for eg:
if v_STR is 43245.67 then it should print as:
43245.67
The above output have is total 18 lenght space filled.

and not
43245.67


I want to send this data to shell script variable.

Thanks,
Re: LPAD space filled output [message #314975 is a reply to message #314971] Fri, 18 April 2008 07:45 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
Show us what you tried and the output. Cut an paste the actuall session, not user rendering of code and output.
Re: LPAD space filled output [message #314977 is a reply to message #314971] Fri, 18 April 2008 07:53 Go to previous messageGo to next message
ritvikd
Messages: 11
Registered: January 2007
Junior Member
The PL/SQL block is huge and as I work in secure environment I wont be able to provide the entire sourecode. All I can provide is the last few statements
IF v_LOCAL_CT_CHARGE IS NULL THEN
        v_CT_CHARGEABLE := '                  '; -- ADD 18 SPACES
    ELSE
        FOR v_LOOPCOUNTER IN 3..21 LOOP
            IF SUBSTR(v_LOCAL_CT_CHARGE,v_LOOPCOUNTER,1) != ' ' THEN
--                dbms_output.put_line(v_LOOPCOUNTER);         
                v_CT_CHARGEABLE := SUBSTR(v_LOCAL_CT_CHARGE,v_LOOPCOUNTER,((21-v_LOOPCOUNTER)+1));
                EXIT;            
            END IF;
                           
        END LOOP; 
        
        v_STR:=LPAD(v_CT_CHARGEABLE,18,' ');
        
    END IF;
    
    dbms_output.put_line(v_STR);     
    
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        v_STR := '                  '; -- ADD 18 SPACES
        dbms_output.put_line(v_STR);



Quote:

The output in my previous post should have been:
||||||||||43245.67

where | is for space

Re: LPAD space filled output [message #314978 is a reply to message #314977] Fri, 18 April 2008 08:00 Go to previous messageGo to next message
Michel Cadot
Messages: 64101
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
set serveroutput on format wrap

Regards
Michel
Re: LPAD space filled output [message #314980 is a reply to message #314977] Fri, 18 April 2008 08:02 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Also, leading/trailing spaces in a shell variable will be probably meaningless since the shell will most likely remove them anyway :

$ > export VAR=BLA
$ > echo $VAR
BLA
$ > export VAR=  BLA
$ > echo $VAR

$ > export VAR="   BLA"
$ > echo $VAR
BLA
$ > export VAR="BLA BLA"
$ > echo $VAR
BLA BLA


icon6.gif  Re: LPAD space filled output [message #314983 is a reply to message #314971] Fri, 18 April 2008 08:02 Go to previous messageGo to next message
ritvikd
Messages: 11
Registered: January 2007
Junior Member
brilliant. Thanks.

when this value is assigned to a shell variable then will shell script variable have spaces? Any idea?
Re: LPAD space filled output [message #314986 is a reply to message #314977] Fri, 18 April 2008 08:12 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
How about v_LOCAL_CT_CHARGE is not null?
icon6.gif  Re: LPAD space filled output [message #315032 is a reply to message #314986] Fri, 18 April 2008 13:09 Go to previous messageGo to next message
ritvikd
Messages: 11
Registered: January 2007
Junior Member
Means??
Re: LPAD space filled output [message #315063 is a reply to message #315032] Fri, 18 April 2008 15:14 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
If v_LOCAL_CT_CHARGE is not null, then the 18 spaces do not get set to the variable.

That's why you have to post COMPLETE code. I just assume that you are appending this variable to some column somewhere in your code and you are wondering why the 18 spaces are not being appended. My answer is that this block of code does not get executed because v_LOCAL_CT_CHARGE is not null;
Re: LPAD space filled output [message #315244 is a reply to message #315063] Sun, 20 April 2008 06:04 Go to previous message
ritvikd
Messages: 11
Registered: January 2007
Junior Member
The problem with the code is that
v_CT_CHARGEABLE := '                  '; -- ADD 18 SPACES
should have been v_STR. It was rectified and tested and
code works fine. The only problem was I was not getting the spaces on the sqlplus editior and that is now resolved by input from Michel Cadot about set serveroutput on format wrap.


Thanks to all for all the assistance provided.

[Updated on: Sun, 20 April 2008 06:08]

Report message to a moderator

Previous Topic: SCHEDULER Program log
Next Topic: PLS-00103
Goto Forum:
  


Current Time: Fri Dec 02 13:51:28 CST 2016

Total time taken to generate the page: 0.09881 seconds