Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any function to add space in PL/SQL

Tags:

plsql

In T-SQL, SPACE() function is used to add spaces to a string. For e.g.

@s = 'He' + space(5) + 'llo'

Output

He     llo

So is there any function in PL/SQL that is equivalent to SPACE()?

Thank you.

like image 663
Sambath Prum Avatar asked Nov 24 '08 02:11

Sambath Prum


2 Answers

You can use RPAD or LPAD functions

select 'He'  || rpad(' ',5,' ') || 'llo'
from dual;
/

or in PL/SQL it would be:

declare
  x varchar2(20);
begin
  x:= 'He'  || rpad(' ',5,' ') || 'llo';
end;
/
like image 86
IK. Avatar answered Sep 23 '22 03:09

IK.


Jeffrey using rpad(' ',n,' ') gives n+1 spaces

select RPAD('A',3,'-')||RPAD(' ',4,' ')||RPAD('B',5,'-') from dual

Output

A--    B----

After A-- and before B, you will find 5 spaces instead of 4.

like image 35
Karuna Avatar answered Sep 23 '22 03:09

Karuna