Tuesday, January 18, 2011

Mysql regex query

Mysql supports regexes into their queries - this is how you would do it.

desc PENDING_ORDER

+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| CustomerID  | varchar(255) | NO   | PRI | NULL    |       | 
| DateCreated | datetime     | NO   |     | NULL    |       | 
| XML_DATA    | text         | NO   |     | NULL    |       | 
| Status      | varchar(20)  | NO   |     | NULL    |       | 
+-------------+--------------+------+-----+---------+-------+

-- find all values that have a new line after the last digit 
 
select XML_DATA as xml from PENDING_ORDER  where XML_DATA REGEXP '[0-9]+\n';

-- Output

< property>
< name> PartnerCustomerID </name>
< value> 999999579
                        </value>
</property>


0 comments: