大家好,我想查询一个字段,一共Varchar2(16)类型,现在的值是FY02600000012345至FY02690000054321我现在想说一下:FY02(60)这里的60可以变的,可以20,70,80,后面的数字是顺序增加,我想问一下怎么查询FY02这四位字母一样,后面10位数字顺序增加的.
select * from aaa where vchcode >='FY02600000012345' and vchcode<=FY02690000054321' 也会查询出:FY02700000000004

解决方案 »

  1.   

    select * from aaa where vchcode like 'FY02%' order by vchcode;
      

  2.   

    怎么不会啊?因为他的大小是先从前面比前的啊。FY0270>FY0260,所以它就不管后面的大小了
      

  3.   

    实践证明:
    我在自己机子上建表t(id int,name var(2))
    insert into 
    'FY02600000012345' 
    FY02690000054321' 
    FY02700000000004
    三条数据
    select * from t where name >='FY02600000012345' and name <='FY02690000054321' 
    结果
    1 FY02600000012345
    2 FY02690000054321
      

  4.   

    楼上的,你把FY02700000000004 改成 FY02600000000004 试试,按要求FY02600000000004是不应该被查询出来的
      

  5.   

    建议LZ自己先试一试再说,要不就是LZ说的数字不对。根据LZ在第一楼中写的要求,你试一试这个语句吧:select * from aaa where substr(a,1,4) = 'FY02' order by substr(a,length(a)-10,10)
      

  6.   

    select * from aaa where a like 'FY02%' order by substring(a,5,10)