NVL return 可以将不同的数据类型作为其参数吗?

can NVL return different data type as its argument?

在下面的查询中,

select NVL(gender, 'not available') from member

我想要在性别为空时查询 returns 'Not Available'。但似乎第二个参数必须与第一个参数具有相同的数据类型。(在此示例中,性别是 CHAR(1),但第二个参数是 VARCHAR 或 CHAR(n) 而不是 CHAR(1)。除了 CHAR(1) 之外还有其他解决方案吗更改 main table 中的数据类型? 我正在使用亚马逊红移。 我也在 group by 中使用 nvl 语句,所以我需要解决方案尽可能简洁。

你可以试试case

select case gender when is null then 'not available' else gender 
from my_table 

这会起作用:

首先找到性别(SELECT 性别来自成员 WHERE .....)

if gender is null
begin
select 'not available' as result
end
else
begin
<-- do your query-->
end