在Oracle SQL查询中使用字符串包含功能 [英] Use string contains function in oracle SQL query

查看:376
本文介绍了在Oracle SQL查询中使用字符串包含功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Oracle数据库,我想知道如何在varchar类型的列中查找行,该列的值包含一个包含某些字符的字符串.

I'm using an Oracle database and I want to know how can I find rows in a varchar type column where the values of that column has a string which contains some character.

我正在尝试类似的操作(这是我想要的一个简单示例),但是它不起作用:

I'm trying something like this (that's a simple example of what I want), but it doesn't work:

select p.name
from   person p
where  p.name contains the character 'A';

我还想知道是否可以使用类似chr(1234)的函数,其中1234是ASCII码,而不是示例查询中的'A'字符,因为在我的情况下,我想在数据库值中搜索人名中包含以ASCII码为8211的字符.

I also want to know if I can use a function like chr(1234) where 1234 is an ASCII code instead of the 'A' character in my example query, because in my case I want to search in my database values where the name of a person contains the character with 8211 as ASCII code.

通过查询select CHR(8211) from dual;,我得到了想要的特殊字符.

With the query select CHR(8211) from dual; I get the special character that I want.

示例:

select p.name
from   person p
where  p.name contains the character chr(8211);

推荐答案

通过我假设您是说表person中的行.您正在寻找的是:

By lines I assume you mean rows in the table person. What you're looking for is:

select p.name
from   person p
where  p.name LIKE '%A%'; --contains the character 'A'

以上是区分大小写的.对于不区分大小写的搜索,您可以执行以下操作:

The above is case sensitive. For a case insensitive search, you can do:

select p.name
from   person p
where  UPPER(p.name) LIKE '%A%'; --contains the character 'A' or 'a'

对于特殊字符,您可以执行以下操作:

For the special character, you can do:

select p.name
from   person p
where  p.name LIKE '%'||chr(8211)||'%'; --contains the character chr(8211)

LIKE运算符匹配一个模式. Oracle文档中详细描述了此命令的语法.您通常会使用%符号,因为这意味着匹配零个或多个字符.

The LIKE operator matches a pattern. The syntax of this command is described in detail in the Oracle documentation. You will mostly use the % sign as it means match zero or more characters.

这篇关于在Oracle SQL查询中使用字符串包含功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆