在oracle sql中搜索pronoum

时间:2018-03-09 08:30:52

标签: sql oracle oracle11g

我有一个法语的文本字段用代词(le,la,les),我想搜索以代词开头的所有行,后跟空格,但是我无法让它工作。

SELECT field, type 
FROM my_search_table 
WHERE UPPER(field) LIKE UPPER('le ' || '%' )
  AND (ROWNUM  <= 6);

查询不返回任何内容

3 个答案:

答案 0 :(得分:0)

SELECT field, type FROM my_search_table 
WHERE UPPER(field) LIKE UPPER('LE%')
OR UPPER(field) LIKE UPPER('LA%')
OR UPPER(field) LIKE UPPER('LES%')

试试这个。

答案 1 :(得分:0)

我会使用这样的正则表达式:

WHERE REGEXP_LIKE (UPPER(field),'LE[[:space:]]+')

这可以找到每一行,其中字段以le开头,后跟一个或多个空格。

答案 2 :(得分:0)

最好使用REGEXP来匹配单词边界中的三个代词(le,la,les)。

SQL Fiddle

Oracle 11g R2架构设置

create table my_search_table AS
select 1 as type, 'La carte'  as field FROM DUAL UNION ALL
select 2 as type,'la mange'  as field FROM DUAL UNION ALL
select 3 as type,'le mange'  as field FROM DUAL UNION ALL
select 4 as type,'Les mange' as field FROM DUAL UNION ALL
select 5 as type,'Il la lance'  as field FROM DUAL UNION ALL
select 6 as type,'language'  as field FROM DUAL UNION ALL
select 7 as type,'lesser'  as field FROM DUAL UNION ALL
select 8 as type,'LAS VEGAS'  as field FROM DUAL 

查询1

SELECT field, TYPE
  FROM my_search_table
 WHERE REGEXP_LIKE (field, '(^|\s)(la|le|les)(\s|$)', 'i')

<强> Results

|       FIELD | TYPE |
|-------------|------|
|    La carte |    1 |
|    la mange |    2 |
|    le mange |    3 |
|   Les mange |    4 |
| Il la lance |    5 |