表A有A、B二个字段,都是varchar2(4)的,里面存起始,截止号码。号码从0001到0000,过了0000就重新从0001排号,我现在想根据前台传过来的4位号码,用between and 查询,怎么办?
打个比方
A B
5000 6000
6001 7000
6001 0100
前台传个6500
可以查到
6001 7000
6001 0100
------解决方案--------------------
WITH test AS(
SELECT '5000' a,'6000' b FROM dual UNION ALL
SELECT '6001','7000' FROM dual UNION ALL
SELECT '6001','0100' FROM dual )
SELECT * FROM test WHERE 0500 BETWEEN a AND (CASE WHEN b<a THEN b+10000 ELSE to_number(b) END)
OR 0500 BETWEEN (CASE WHEN b<a THEN b-10000 ELSE to_number(b) END) AND a