如何用sql语句,判断数据库中某字段的内容,包含于某字符串?也就是属于某字符串的子串?
比如数据库中某字段内容为“张三”,某字符串是“张三是好人”,则符合条件,
如果数据库中某字段内容为“张三”,某字符串是“张”,则不符合条件,
黄舟2017-04-17 11:08:11
select * from table t where t.a like '%'||t.b||'%'; select * from table t where t.a like '%'||var||'%'
(PL/SQL, fields a and b must be of string type, var is a string variable in the program, or more precise matching can use regular expressions, but the method is the same through string concatenation)
大家讲道理2017-04-17 11:08:11
where "%张三% like column_name
sry The above is written backwards, it should be like this. If it is not mysql, the splicing method may be different.
where '张三' like concat('%', column_name, '%')
ringa_lee2017-04-17 11:08:11
SELECT *
FROM aaa
where instr('$var',aaa.city)
I found this from the Internet and found it useful.
PHP中文网2017-04-17 11:08:11
Use a concat function. You can turn the variable you want to match into something similar to a regular expression. For example: there are two fields in the user table, one is called username and the other is password. If you first want Find the line containing username in password, you can write it like this:
select username,password from user where password like concat('%',username,'%');