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