how to trim leading zeros from alphanumeric text in mysql function

You are looking for the trim() function.

Alright, here is your example

SELECT TRIM(LEADING '0' FROM myfield) FROM table

TIP:

If your values are purely numerical, you can also use simple casting, e.g.

SELECT * FROM my_table WHERE accountid = '00322994' * 1

will actually convert into

SELECT * FROM my_table WHERE accountid = 322994

which is sufficient solution in many cases and also I believe is performance more effective. (warning - value type changes from STRING to INT/FLOAT).

In some situations, using some casting function might be also a way to go:

http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html

Tags:

Mysql