Home » SQL & PL/SQL » SQL & PL/SQL » lpad (oracle 10g)
lpad [message #404984] Tue, 26 May 2009 00:17 Go to next message
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 #404991 is a reply to message #404984] Tue, 26 May 2009 00:37 Go to previous messageGo to next message
Michel Cadot
Messages: 63924
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Still unable to follow the guidelines?
Still unable to read the documentation?
What don't you understand in LPAD? How can someone don't understand LPAD??? If you really don't I stringly recommend you to change job and find something that is in your skills which is obviously not something related to computer science.

Re: lpad [message #405046 is a reply to message #404991] Tue, 26 May 2009 03:19 Go to previous message
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.
Previous Topic: TRUNCATE TABLE inside a package giving Compilation Error
Next Topic: Setting up a database link
Goto Forum:

Current Time: Wed Oct 26 04:34:49 CDT 2016

Total time taken to generate the page: 0.08198 seconds