## LPAD(x,a,y,n)

LPAD(x,a,y,n) is a string function that inserts the character string y (string literal) at the start of the character string x (string specification) as often as specified by the expression a. Only expressions that supply an alphanumeric value are permitted as string specifications. The result of the expression a must be a positive integer.

Leading and subsequent blanks in the character string x are truncated.

The optional parameter n (unsigned integer) defines the maximal total length of the character string created. n must be greater than or equal to the total LENGTH(x)+a*LENGTH(y).

| Result of the LPAD(x,a,y,n) function
LPAD(x,a,y) x must identify a CHAR or VARCHAR column. | The maximum length of the character string is the length of the character string x.
x or a is the NULL value | NULL value
a is the special NULL value | Error message

SELECT hno, LPAD(' ',TRUNC(price/10),'*',70) graph
FROM room WHERE price > 150 ORDER BY price DESC

Creating bar charts: LPAD inserts asterisks in front of the first parameter (in this case, a blank). This is done according to the number equal to price divided by 10.

HNO | GRAPH
130 | **********************************************************************
140 | ************************************************************
50 | **************************************************
60 | **************************************************
150 | *********************************************
80 | ****************************************
120 | ***********************************
90 | ******************************
130 | ***************************
10 | ********************
60 | ********************
140 | ********************
150 | *******************
50 | ******************
70 | ******************
130 | ****************

See also:

RPAD(x,a,y,n)