简体   繁体   English

Oracle SQL查询

[英]Oracle sql queries

I am working on a small relational database for school and having trouble with a simple query. 我正在为学校使用小型关系数据库,但在进行简单查询时遇到了麻烦。 I am supposed to find all records in a table that have a field with the word 'OMG' somewhere in the text. 我应该在表中找到所有记录,这些记录中的某处在字段中带有单词“ OMG”。 I have tried a few other and I can't figure it out. 我尝试了其他一些方法,但无法解决。 I am getting an invalid relational operator error. 我收到无效的关系运算符错误。

my attempts: 我的尝试:

select * from comments where contains('omg');
select * from comments where text contains('omg');
select * from comments where about('omg');

and several more variations of the above. 以及上述内容的其他几种变体。 As you can see I am brand spanking new to SQL. 如您所见,我是SQL的新手。 text is the name of the field in the comments table. text是注释表中字段的名称。

Thanks for any help. 谢谢你的帮助。

Assuming that the column name is text : 假设列名称为text

select * from comments where text like '%omg%';

The percentage % is a wild-card which means that any text can come before/after omg 百分比%是通配符,表示任何文本都可以在omg之前/之后出现

Pay attention, if you don't want the results to contain words in which omg` is a substring - you might want to consider adding whitespaces: 请注意,如果您不希望结果包含以omg`作为子字符串的单词-您可能需要考虑添加空格:

select * from comments where text like '% omg %';

Of course that it doesn't cover cases like: 当然,它不涵盖以下情况:

  • omg is at the end of the sentence (followed by a ".") omg在句子的末尾(后跟“。”)
  • omg has "!" omg有“!” right afterwards 之后
  • etc 等等

您可能要对通配符(%)使用LIKE运算符

SELECT * FROM comments WHERE text LIKE '%omg%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM