MySQL中利用正则表达式查询指定开头与指定结尾的字符串
建表regexp_example:create table regexp_example(prod_name varchar(10) not null default '',prod_price smallint unsigned not null default 0)engine myisam character set utf8;# regexp_example表结构说明:...
·
建表regexp_example:
create table regexp_example(
prod_name varchar(10) not null default '',
prod_price smallint unsigned not null default 0
)engine myisam character set utf8;
# regexp_example表结构说明:
# prod_name表示产品名称,prod_price表示产品价格
向regexp_example表中插入数据:
insert into regexp_example values
('HTCN12',1999),
('HTCN250',2899),
('HTCNXP',4999),
('ASHTCN09',999)
('HTCN85',1799);
查询场景:从regexp_example表中查询出所有名称形如"HTCNxx"的产品的信息,"HTCNxx"中结尾处的两个x均指的是在0-9之间的任意一个数字。
实现上述查询任务的SQL语句如下:
select * from regexp_example where prod_name REGEXP '^HTCN.{0}[0-9]{2}$';
查询结果如下图所示:
更多推荐
已为社区贡献4条内容
所有评论(0)