[英]sql select where column value exists in a text
我正在寻找类似操作员的逆转。 我有很长的文字和一个单词的SQL表。 我想选择文本中存在的单词。 像这样的东西:
select word from mytable where word in ('this is a long story')
SELECT word
FROM mytable
WHERE INSTR('this is a long story', word) > 0
函数INSTR是多字节安全的,并且仅当至少一个参数是二进制字符串时才区分大小写。 希望能帮助到你。
你可以使用CHARINDEX
select word from mytable where CHARINDEX(word , 'this is a long story') > 0
这可以是DB依赖的,例如使用postgreSQL,你可以这样做:
select word from mytable where word in (select regexp_split_to_table('this is a long story', E'\\s+') );
其他数据库也有类似的功能。
select word from mytable where 'this is a long story' like '%' || word || '%'
你的意思是这样的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.