关于db2 between and 的疑问

xug05 2008-03-28 04:26:04
关于db2 between and 的疑问
假设table: A(column VARCHAR(18))其中存有身份证号码。身份证号除末尾含字母,其他为数字。
用select * from A where substr(column,9,2) between '00' and '99' ,不能排除如‘55013419681M032016’这样的记录。
请问这是怎么一回事?
...全文
1297 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
nemo26 2008-04-02
  • 打赏
  • 举报
回复
substr(indx,len),是截取从第indx开设len长的字符串,你可能理解错了,与java里的不同。
bubble1000 2008-03-28
  • 打赏
  • 举报
回复
--呵呵,看来还是旁观者清啊,你不是between '00' and '99'吗,这条记录substtr完后是68,当然在这之间了。怎么能排除呢。要排除加个not:
Select * from (values substr('55013419681M032016',9,2),'99','00') as test(id) where id not between '00' and '99';
我觉得如果确定substr完后不包括字母还是转成数值行再做:
Select * from (values substr('55013419681M032016',9,2),'99','00') as test(id) where int(id) <0 and int(id) >99;
条件当然也可以变:
Select * from (values substr('55013419681M032016',9,2),'99','00') as test(id) where int(id) >=0 and int(id) <=99;

5,889

社区成员

发帖
与我相关
我的任务
社区描述
IBM DB2 是美国IBM公司开发的一套关系型数据库管理系统,它主要的运行环境为UNIX(包括IBM自家的AIX)、Linux、IBM i(旧称OS/400)、z/OS,以及Windows服务器版本
社区管理员
  • DB2
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧