【问题标题】:Mysql: link records with special characters to the very first alphabet after the special characters and retriveMysql:将带有特殊字符的记录链接到特殊字符之后的第一个字母并检索
【发布时间】:2015-09-25 20:50:11
【问题描述】:

 

create table temp_surnames( last_name varchar(100) not null primary key, create_date datetime not null);

insert into temp_surnames (last_name) values('$$moses’);
insert into temp_surnames (last_name) values(‘\'moses’);
insert into temp_surnames (last_name) values('moses’);
insert into temp_surnames (last_name) values(‘ammoses');

我想检索除“ammoses”之外的所有记录。基本上每条以m% 开头的记录,但如果我使用'%m%',都会返回所有记录。请推荐。

【问题讨论】:

  • 改用正则表达式,并排除/包含您想要允许的任何前缀字符。使用like 和通配符这样做会非常低效。
  • @MarcB:谢谢。是的正则表达式有效。

标签: mysql database select special-characters


【解决方案1】:

一个简单的正则表达式应该是这样的:

where last_name regexp '^[^[:alpha:]]*m'

【讨论】:

  • 行得通!谢谢!我确实有一个额外的以下问题:如何使用上述内容:SELECT last_name FROM temp_surnames WHERE last_name CONCAT(last_name, '%') ORDER BY last_name
  • 我不确定您的查询要做什么,但是这个where 条件可以只是您查询中的where 子句。
猜你喜欢
  • 2016-03-12
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-14
  • 1970-01-01
相关资源
最近更新 更多