If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > LTRIM function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-12-09, 05:12
sushma007 sushma007 is offline
Registered User
 
Join Date: Aug 2007
Posts: 64
Thumbs down LTRIM function

Hi Friends ,

In Oracle we have LTRIM function that takes two arguments .
In Oracle the following example trims all of the left-most x's and y's from a string:

Quote:
SELECT LTRIM('xyxXxyLAST WORD','xy')
FROM DUAL;

Result : XxyLAST WORD
I tried to reproduce this functionality in MySQL, but LTRIM function in MySQL accepts only one argument . I tried with
Quote:
TRIM(LEADING 'xy' from 'xyxXxyLAST WORD')
But this gives a different result .

Please suggest me .
Reply With Quote
  #2 (permalink)  
Old 02-12-09, 06:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
suggest you what?

the example you gave doesn't make sense

and what if there is no immediate equivalent function -- can you explain in words what you want to do?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-12-09, 07:19
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
It doesn't surprise me that Oracles LTRIM doesn't work it looks a very very odd way of naming/implementing a REPLACE function, every one else Im aware of uses LTRIM/RTRIM./TRIM to remove leading or trailing spaces

MySQL :: MySQL 5.1 Reference Manual :: 11.4 String Functions
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 02-12-09, 07:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
TRIM can remove other characters besides spaces

the problem with the given example is that while the oracle function appears like it might be removing sets of pairs of characters, the given example doesn't look right
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-12-09, 08:21
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
agreed oracle LTRIM offers that, but MySQL LTRIM doesn't. Like you Im not convinced that there is a direct MySQL repalcement for what is claimed for the Oracle LTRIM fucntion... the closest I coudl see was REPLACE. but y'never know
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #6 (permalink)  
Old 02-12-09, 08:27
buckeye234 buckeye234 is offline
Registered User
 
Join Date: Sep 2002
Location: Ohio
Posts: 204
Quote:
Originally Posted by r937
the problem with the given example is that while the oracle function appears like it might be removing sets of pairs of characters, the given example doesn't look right
With the LTRIM function, Oracle treats the characters in the second argument as a list. It will remove any of the characters, in any combination, on the left side of the first argument until it reaches a character that is not in the list.
Reply With Quote
  #7 (permalink)  
Old 02-12-09, 08:48
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
I think MySQL is working on using regular expressions with the replace command - this would then handle this sort of thing easily. Sadly it hasn't been implemented yet.

Of course you could also avoid hiring data entry people with Tourette's and then you won't get the XXXX at the start of each name.
Reply With Quote
  #8 (permalink)  
Old 02-12-09, 10:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by buckeye234
... until it reaches a character that is not in the list.
aha, the penny drops, thanks very much

TRIM(LEADING 'y' FROM TRIM(LEADING 'x' FROM daString))

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 02-12-09, 10:35
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Won't that just leave you with "xXxyLAST WORD"?
Reply With Quote
  #10 (permalink)  
Old 02-12-09, 10:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yes, you're right, mike, good catch

sushma, perhaps you should be trimming in the front end app?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On