Oracle SQL--解码为多个元素
我可以创建一个连接条件,如:Oracle SQL--解码为多个元素,sql,oracle,decode,Sql,Oracle,Decode,我可以创建一个连接条件,如: table1.value_1 = decode(table2.encoded_value,1,'a',2,'b',3,'c') 但是如果我需要进行类型内联接呢 e、 g。 我如何编写解码以实现以下功能: table1.value_1 in decode(table2.encoded_value, 1, 'a', 2, 'b', 3, 'c',
table1.value_1 = decode(table2.encoded_value,1,'a',2,'b',3,'c')
但是如果我需要进行类型内联接呢
e、 g。
我如何编写解码以实现以下功能:
table1.value_1 in
decode(table2.encoded_value,
1,
'a',
2,
'b',
3,
'c',
4,
('d','e','f')
);
此语法无效,但其思想是,在table2.encoded_值为4的情况下,条件将变为table1.value_1 in('d','e','f')。我认为这是不可能的,您应该改为更改查询的算法 不必检查
值_1
是否在某个范围内,您可以如下更改算法:
(table2.encoded_value <> 4
and table1.value_1 = decode(table2.encoded_value,
1, 'a',
2, 'b',
3, 'c'))
or table2.encoded_value = 4 and table1.value_1 in ('d', 'e', 'f'/*Or a select of multiple values*/)
(表2.4)
表1.value_1=解码(表2.code_值,
1,"a",,
2,‘b’,
(三)("c")
或在('d'、'e'、'f'/*或多个值的选择*)中的table2.encoded_value=4和table1.value_1
我认为这是不可能的,您应该更改查询的算法
不必检查值_1
是否在某个范围内,您可以如下更改算法:
(table2.encoded_value <> 4
and table1.value_1 = decode(table2.encoded_value,
1, 'a',
2, 'b',
3, 'c'))
or table2.encoded_value = 4 and table1.value_1 in ('d', 'e', 'f'/*Or a select of multiple values*/)
(表2.4)
表1.value_1=解码(表2.code_值,
1,"a",,
2,‘b’,
(三)("c")
或在('d'、'e'、'f'/*或多个值的选择*)中的table2.encoded_value=4和table1.value_1
您通常不会使用函数。你只需要使用布尔逻辑
WHERE (table2.encoded_value = 1 AND table1.value_1 = 'a')
OR (table2.encoded_value = 2 AND table1.value_1 = 'b')
OR (table2.encoded_value = 3 AND table1.value_1 = 'c')
OR (table2.encoded_value = 4 AND table1.value_1 in( 'd', 'e', 'f'))
通常不会使用函数。你只需要使用布尔逻辑
WHERE (table2.encoded_value = 1 AND table1.value_1 = 'a')
OR (table2.encoded_value = 2 AND table1.value_1 = 'b')
OR (table2.encoded_value = 3 AND table1.value_1 = 'c')
OR (table2.encoded_value = 4 AND table1.value_1 in( 'd', 'e', 'f'))