lpad [message #404984] |
Tue, 26 May 2009 00:17  |
ramesh55.sse
Messages: 262 Registered: December 2008 Location: Hyderabad
|
Senior Member |
|
|
Hi Experts
Some body this query to sort varchar2 column that contains
numbers and names.But i didn,t understand how LPAD works in sorting Please explain me.
select x from a order by lpad(x,10,' ');
|
|
|
|
Re: lpad [message #405046 is a reply to message #404991] |
Tue, 26 May 2009 03:19  |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
The OP didn't say that he didn't understand LPAD - he said that he didn't understand how to use LPAD in sorting - a very different issue.
@Ramesh - string sorting is done by comparing the left hand character of two strings - the string with the lower value comes first.
Within any two strings with the same left hand character, the next most left hand characters are inspected until a difference is found.
This differs significantly to sorting for numbers - the number 9 is smaller than the number 11, but the string '9' is larger than the string '11'
If you want to compare strings, it frequently helps to left pad the strings with spaces to get them all to the same length, and this is what LPAD is used for.
|
|
|