选择查询不起作用

时间:2016-06-21 13:44:57

标签: sql oracle oracle11g

查询:

select * 
from etm 
where emp_id LIKE '009090%'
  AND directnumber LIKE '111 123 12345x 67%'
  AND cellnumber LIKE '123456789%'
  AND phone LIKE '111 123 12345x 67';

数据库:oracle 11g

当LIKE运算符中包含小X字符(12345 x )时,选择查询不会返回任何记录。

当我用任何其他字符(小/大写)替换它时((12345 Y )),但用小x替换它也不起作用。

我无法修改查询,在插入数据时是否可以在数据库级别完成任何操作? 我们正在批量导入数据。

2 个答案:

答案 0 :(得分:0)

我看不出问题 - 这是一个展示的测试用例:

with sample_data as (select '123x 456' str from dual union all
                     select '123 456' str from dual union all
                     select '123x' str from dual union all
                     select 'abcx 93s' str from dual)
select *
from   sample_data
where  str like '123x%';

STR     
--------
123x 456
123x    

因此,您可以看到我的搜索已经撤回了str列以123x开头的行。

但是,如果我搜索以123y开头的行,则不会返回任何行:

with sample_data as (select '123x 456' str from dual union all
                     select '123 456' str from dual union all
                     select '123x' str from dual union all
                     select 'abcx 93s' str from dual)
select *
from   sample_data
where  str like '123y%';

no rows selected.

因为str列没有以123y开头的行。

您的数据是否类似,如果在x个条件中有一个或多个like,则没有任何行匹配所有过滤条件?

答案 1 :(得分:0)

我尚未验证此查询,但它应该有效。

select * 
from etm 
where emp_id LIKE '009090%'
  AND (directnumber LIKE '111%' or directnumber LIKE '123%' .....)
  AND cellnumber LIKE '123456789%'
  AND (phone LIKE '111' or phone LIKE '123' .......);

参考: https://community.oracle.com/thread/1096523?start=0&tstart=0

相关问题