Good morning my beloved sql wizards and sorcerers,
早上好,我亲爱的sql巫师和巫师,
I am wanting to substitute on 3 columns of data across 3 tables. Currently I am using the NVL function, however that is restricted to two columns.
我想要在3个表中替换3列数据。目前我正在使用NVL功能,但是这仅限于两列。
See below for an example:
请参阅下面的示例:
SELECT ccc.case_id,
NVL (ccvl.descr, ccc.char)) char_val
FROM case_char ccc, char_value ccvl, lookup_value lval1
WHERE
ccvl.descr(+) = ccc.value
AND ccc.value = lval1.descr (+)
AND ccc.case_id IN ('123'))
case_char table
case_id|char |value
123 |email| work_email
124 |issue| tim_
char_value table
char | descr
work_email | complaint mail
tim_ | timeliness
lookup_value table
descr | descrlong
work_email| xxx@blah.com
Essentially what I am trying to do is if there exists a match for case_char.value with lookup_value.descr then display it, if not, then if there exists a match with case_char.value and char_value.char then display it.
基本上我要做的是,如果case_char.value与lookup_value.descr存在匹配,则显示它,否则显示它,如果存在与case_char.value和char_value.char的匹配则显示它。
I am just trying to return the description for 'issue'from the char_value table, but for 'email' I want to return the descrlong from the lookup_value table (all under the same alias 'char_val').
我只是想从char_value表中返回'issue'的描述,但对于'email',我想从lookup_value表中返回descrlong(所有这些都在同一个别名'char_val'下)。
So my question is, how do I achieve this keeping in mind that I want them to appear under the same alias.
所以我的问题是,如何实现这一点,请记住,我希望它们出现在相同的别名下。
Let me know if you require any further information.
如果您需要任何进一步的信息,请告诉我。
Thanks guys
多谢你们
2 个解决方案
#1
12
You could nest NVL:
你可以嵌套NVL:
NVL(a, NVL(b, NVL(c, d))
But even better, use the SQL-standard COALESCE, which does take multiple arguments and also works on non-Oracle systems:
但更好的是,使用SQL标准COALESCE,它确实采用多个参数,也适用于非Oracle系统:
COALESCE(a, b, c, d)
#1
12
You could nest NVL:
你可以嵌套NVL:
NVL(a, NVL(b, NVL(c, d))
But even better, use the SQL-standard COALESCE, which does take multiple arguments and also works on non-Oracle systems:
但更好的是,使用SQL标准COALESCE,它确实采用多个参数,也适用于非Oracle系统:
COALESCE(a, b, c, d)