《mysql必知必会》学习_第9章

 第九章,用正则表达式进行搜索。

P52

select prod_name from products where prod_name regexp '1000' order by prod_name; #regexp后面所跟着的文字为正则表达式,regexp匹配任何的字符#

select prod_name from products where prod_name regexp '.000' order by prod_name; #点(.)表示匹配任何的字符#

LIKE和REGEXP的区别,LIKE匹配的是整个列,REGEXP匹配的是一个列的完整或者一段,例如,like ‘huan’  返回 huan ;而regexp ‘huan’返回 ‘huan 也返回 xxhuanxx ;当LIKE加上通配符的时候,可以相当于EXGEXP。

P54

select prod_name from products where prom_name regexp '1000|2000' order by prod_name ; #符号竖直杠(|)功能相当于or,但此处不可用or 替代#

P55

select prod_name from products where prod_name regexp '[123] ton' order by prod_name ; #[123] ton 表示匹配的字段含有 1 ton或者2 ton或者3 ton , [ ]是or是另一种形式的or语句,和下面的语句表达同样的意思#

P56 

[0123456789] 表示匹配0到9,可以用[0-9]简化。

select prod_name from products where prod_name regexp '[1-5] ton' order by prod_name; #正则表达式检索 x1 tonx 到 x5 tonx #

select vend_name from products where vend_name regexp '.' order by vend_name;  #点(.)表示匹配任何字符,所以返回的结果是每个行都被检索出来。#

 

P57

 select vend_name from products where vend_name regexp '\\.' order by vend_name;  #点(.)表示匹配任何字符,所以返回的结果是每个行都被检索出来。当要检索点. 时候,\\为前导,表示查找,\\.表示查找.#

注意:匹配斜杠时候,是regexp '\\\' 。

P61

select 'hello' regexp from '[0-9]'; #可以在自定义的一段字段里面搜索,不用指定表,返回0表示结果为 hello中没有数字#

注意: 当编写语句时候,’ ‘没有对应上,就算已经用;,还是表示该语句没有结束,可以其他符号也会像这个一样有始有终吧,我暂时没发现其他的。如下图#

 

posted @ 2018-07-31 16:25  张三疯了  阅读(135)  评论(0编辑  收藏  举报