[英]SQL Select Statement(REGEXP) to find special characters and numbers in an alpha only field
I am using mySQL to query a field which would be LastName
. 我正在使用mySQL查询将是
LastName
的字段。 I am looking for any errors in the field such as any special characters or numbers. 我正在寻找该字段中的任何错误,例如任何特殊字符或数字。 I am not terribly familiar with SQL so this has been a challenge so far.
我对SQL并不是很熟悉,所以到目前为止,这一直是一个挑战。 I have written simple statements with
REGEXP
but I have run into some issues the REGEXP
i was using was: 我已经用
REGEXP
编写了简单的语句,但是遇到了一些我使用的REGEXP
问题:
SELECT LastName FROM `DB`.`PLANNAME` where LastName REGEXP '^([0-9])'
now this turned up results where numbers were the first character in the string and i realized that if anything was in the middle of the string that started with a letter this would not pick it out. 现在结果出现了,数字是字符串中的第一个字符,我意识到如果字符串中间有任何以字母开头的字符,它将不会被选中。
To be clear i just need to find the errors not write a code to clean them out. 为了清楚起见,我只需要找到错误而不是编写代码来清除它们。
Any help would be greatly appreciated 任何帮助将不胜感激
Thanks 谢谢
Pete 皮特
Maybe you are looking for something like this: 也许您正在寻找这样的东西:
SELECT LastName FROM `DB`.`PLANNAME` WHERE NOT LastName REGEXP '[A-Za-z0-9]';
Here is a documentation on this: 这是关于此的文档:
Table 12.9 String Regular Expression Operators 表12.9字符串正则表达式运算符
Something like this should do it for you. 这样的事情应该为您做。
SELECT column FROM table WHERE column REGEXP '[^A-Za-z]'
This will return any rows where a character that is not az. 这将返回任何非z字符的行。 You might want to add in
您可能要添加
and
'
. 和
'
。 For O'brien
s and von lansing
etc. Any characters you think are acceptable should go in the character class []
, http://www.regular-expressions.info/charclass.html . 对于
O'brien
和von lansing
等。您认为可以接受的任何字符都应该放在字符类[]
, http://www.regular-expressions.info/charclass.html 。
Demo: https://regex101.com/r/nC9cG7/1 演示: https : //regex101.com/r/nC9cG7/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.