Pad Characters on the Right Side of a String in Oracle

Pad Characters on the Right Side of a String in Oracle

  • SQL
  • 1 min read

In Oracle, you can use the rpad() function to pad specific characters on the right side of a string in Oracle.

RPAD() Function Syntax

rpad(expr1, n, expr2)

The result of RPAD is expr1 plus an arbitrary number of repetitions of expr2 for right padding until it reaches length n characters. A query's results can be neatly formatted with the help of this function.

Padding Characters Right Side of a String in Oracle Example

The following SQL query pads the asterisks to the numeric value:

select rpad('8993.22', 10, '*') from dual;

Output:

8993.22***

Using RPAD() in PL/SQL Program

Below PL/SQL program, adds the dollar sign to the right side of a string using the rpad() function:

declare
  v_string varchar2(100);
begin
  v_string := rpad('Oracle', 15, '$');
  dbms_output.put_line(v_string);
end;

Output:

Oracle$$$$$$$$$

See also: