我有一个Oracle选择,如下所示:
SELECT *
FROM CUSTOMER
WHERE (CUSTOMER_TYPE BETWEEN 100 AND 200
OR CUSTOMER_TYPE = 350
OR CUSTOMER_TYPE BETWEEN 410 AND 520);
我想将其更改为在同一语句中结合多个范围和单个值的评估的内容。以下语法是不正确的,但有一些Oracle等价吗?
SELECT *
FROM CUSTOMER
WHERE CUSTOMER_TYPE IN (100..200, 350, 410..520);
答案 0 :(得分:0)
将此视为一种可能性。
SELECT *
FROM CUSTOMER c,
(
select level + 99 n from dual connect by level < 102
union all
select 350 n from dual
union all
select level + 409 n from dual connect by level < 112
) t
WHERE c.CUSTOMER_TYPE = t.n
它避免了 OR 和 IN 。如果幸运的话,结果就是哈希联接。