开发者

Select query with regular expression - MySql

开发者 https://www.devze.com 2023-01-16 19:54 出处:网络
I want to select records if a particular column has numbers in its name. Table 1 IDEmpCodeEmpName 11CName1

I want to select records if a particular column has numbers in its name.

Table 1

ID   EmpCode    EmpName
1    1C         Name1
2    2C        开发者_高级运维 Name2
3    C3         Name3
4    CD         Name4
5    CD         Name4
6    C6D        Name6
7    7CD        Name7

I need to select records 1,2,3,6,7 based on EmpCode. How can this be performed?

EDIT: EmpCode can have number in any position


SELECT * FROM table WHERE EmpCode REGEXP '[0-9]'

Or alternatively, if you want to check for 'starts with a digit' instead of 'contains a digit':

SELECT * FROM table WHERE EmpCode REGEXP '^[0-9]'

Edit: REGEXP (not REGEX) is the correct function name...

0

精彩评论

暂无评论...
验证码 换一张
取 消