I am trying to dynamically fetch the value of column named 'abc' using the text that is deduced from the decode function. Decode function is returning the text value of the column, that is 'abc' but not the underlying value dynamically. Is there a way to do this?
SELECT LOWER(DECODE('METRIC','METRIC','abc','MODEL','xyz','COUNTRY','US')) as abc FROM table_test
Expected result:
abc
---
1.2
1.5
1.6
1.7
table_test:
If you can't use columns as the values in DECODE
, you may always write a regular CASE
expression:
SELECT
CASE metric WHEN 'METRIC' THEN abc
WHEN 'MODEL' THEN xyz
WHEN 'COUNTRY' THEN US END AS output
FROM table_test;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.