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 produce 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).
x, a, y, n |
Result of the LPAD(x,a,y,n) function |
---|---|
LPAD(x,a,y) and 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 a NULL value |
NULL value |
a is a special NULL value |
Error Messages |
Example
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 |
**************** |