日期:2014-05-17  浏览次数:20752 次

关于ORACLE11G模糊查询的疑问
数据库中有一个表格customers,其中表格中有company的值为Smithson Corp.的一条记录,现在想要通过LIKE查询该记录,但是无法查到,下面是两个查询的语句:
第一个是使用%查询:
select company, credit_limit 
from customers 
where company like '%mithson Corp.';
注:如果是将%放置放置Smithson Corp.末尾是可以查询的。
第二个是使用_查询:
select company, credit_limit 
from customers 
where company like 'mithson Cor_.';

------解决方案--------------------
%匹配任意(0-n)个字符,'%mithson Corp.'查不到而'%mithson Corp.%'可查到,说明.后面还有字符
你可用length('Smithson Corp.')和length(company)看下两者大小是否相等,按你说的肯定后面的大,可能是其他字符而实际你看不出来

_匹配一个字符