我有一个查询
SELECT CAST(p.propertyId AS long) FROM Property p
WHERE p.propertyId IS NOT NULL
AND p.propertyId NOT LIKE '%-%'
AND p.propertyId NOT LIKE '%+%'
因为WHERE条件成功滤除了propertyId的所有非数字值,所以该方法很有效。但是如果我尝试使用演员表作为条件
SELECT p FROM Property p
WHERE p.propertyId IS NOT NULL
AND p.propertyId NOT LIKE '%-%'
AND p.propertyId NOT LIKE '%+%'
AND CAST(p.propertyId AS long) BETWEEN 999999 AND 10000000
它失败,并显示错误
java.sql.SQLException: ORA-01722: invalid number
。有没有一种方法可以强制最后一个条件只检查前三遍?
最佳答案
如果您的第一个请求过滤掉了所有非数字值,则可以从其结果中进行选择:
SELECT p FROM
(
SELECT p1 FROM Property p1
WHERE p1.propertyId IS NOT NULL
AND p1.propertyId NOT LIKE '%-%'
AND p1.propertyId NOT LIKE '%+%'
)
where CAST(p.propertyId AS long) BETWEEN 999999 AND 10000000