w3resource

Oracle RPAD function

Description

The Oracle RPAD function is used to pad the right side of a string with a specific set of characters. This function is useful for formatting the output of a query.

The string cannot be null. If expr2 not specified then it defaults to a single blank. If the original string (expr1) is longer than the specified length (n), the function returns a truncated version of expr1 that fits within n characters.

Uses of Oracle RPAD Function
  • Basic Right Padding: Add a specific set of characters to the right side of a string to achieve a desired total length.

  • Formatting Query Output: Format output by padding strings with characters such as spaces, asterisks, or other symbols.

  • Creating Simple Charts: Generate visual representations of data, such as charts or graphs, by padding strings to represent values graphically.

  • Ensuring Uniform String Length: Ensure that strings have a uniform length for alignment in tabular data displays.

Syntax:

RPAD(expr1 , n [, expr2 ])

Parameters:

Name Description Data Types
expr1 Original string. CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB
n A number indicating the total length of the string ( in characters) returned after padding. NUMBER integer or a value that can be implicitly converted to a NUMBER integer.
expr2 String which is used for left padding. CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB

Return Value Type

CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB

Applies to

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Pictorial Presentation

Oracle RPAD function pictorial presentation

Examples: Oracle RPAD function

The following example creates a simple chart of salary amounts by padding a single space with asterisks:

SELECT last_name, RPAD(' ', salary/1000/1, '*') "Salary"
FROM employees
WHERE department_id = 80
ORDER BY last_name, "Salary";

Sample Output:

LAST_NAME               Salary
----------------------------------
Alberto                 ***********
Allan 			********
Alyssa 			*******
Amit 			*****
Charles 		*****
Christopher 		*******
Clara 			*********
Danielle 		********
David 			*****
David 			********
Eleni 			*********
Elizabeth 		******
Ellen 			**********
. . .

Previous: REPLACE
Next: RTRIM



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/oracle/character-functions/oracle-rpad-function.php