PDA

View Full Version : Numers With MySQL



Gonzo
September 12th, 2001, 16:42
Is there a way to get all the numbers from a MySQL database, just results that start with a number?

Thanks

BillWill
September 12th, 2001, 20:23
Can you explain better or shows us a sample table structure? I'm not sure if you mean searching a every column or just a specific one.

jm4n
September 13th, 2001, 06:40
If I'm reading you correctly, you want to look for entries in a char/varchar column which are digits. If so, you simply need a regular expression. Perhaps something like this (untested) would do:

mysql> select foo from bar where field rlike "^[0-9]";

The above assumes you're looking for anything starting with a digit. If the field should be all digits:

mysql> select foo from bar where field rlike "^[0-9]+$";

Learn regular expressions; they can be your best friend :)

Gonzo
September 13th, 2001, 07:00
Thank you jm4n, the first one was what I was looking for.

Also do you know where I can regular expressions?

jm4n
September 14th, 2001, 15:25
I first learned regular expressions by learning Perl (which is well worth learning itself). Perl's regular expressions are by far the most robust implementation (not to mention fast). If you've never used regular expressions, they open up a whole new world to a programmer.

Orielly has a great book on regular expressions; I don't have it handy and am too lazy to search, but I believe it's "Mastering Regular Expressions" or something to that effect. "Learning Perl" (also Orielly) touches on them as well.

Once you get the basic idea, you can apply them in many places: PHP, MySQL, grep, even C with the right libraries.