我有一个oracle查询,其中一部分是使用DECODE计算一些值.例如:
SELECT ...,(SELECT DECODE((SELECT 23 FROM DUAL),null,(SELECT 23 FROM DUAL)) FROM DUAL) FROM ...
这里值“23”在运行时计算,它是非常复杂的连接 – 多个表,使用PARTITION BY等.所以我想避免在值不是“0”时执行相同的子查询.有没有办法写这样的东西
SELECT ...,(SELECT DECODE ((SELECT 23 FROM DUAL) as test,test) FROM DUAL) FROM ...
解决方法
这对你有用吗?
我刚刚将“23”移动到带有描述性别名的内联表中.
我刚刚将“23”移动到带有描述性别名的内联表中.
select ...,( select decode ( computed_value.val,computed_value.val ) from (select 23 as val from dual) computed_value ) from ...
CASE声明也可能增加清晰度,如:
select ...,case when computed_value.val = 0 then null else computed_value.val end as my_field from (select 23 as val from dual) computed_value ...