January 12 2013

Mysql lpad() function

Tagged Under : ,

MySQL
Using Mysql function add asterisk (*) in front of the string.

Example Output:
********MyTestString
*******MyTestString2
**********TestString

lpad, one of the functions from MySQL which able do that

Sample Data:
IdNameDate
1MyTestString2013-01-1
2MyTestString22013-01-5
3TestString2013-01-5

Using Syntax below you able get the result like above example

Syntax:
LPAD(str, len, padstr)
Example:
SELECT LPAD(Name, 20, '*') as name FROM TABLE
Output:
name
---------------------
********MyTestString
*******MyTestString2
**********TestString

Make a Comment

You must be logged in to post a comment.