在上次基础上,添加空值判断:
一.直接判断
select case when s1 is null then s1 when s2 is null then s1 when s3 is null then greatest(s1,s2) when s4 is null then greatest(s1,s2,s3) when s5 is null then greatest(s1,s2,s3,s4) when s6 is null then greatest(s1,s2,s3,s4,s5) when s6 is not null then greatest(s1,s2,s3,s4,s5,s6) end as a from test;
二.将判断条件写成函数调用
create or replace function max_value(s1 varchar2,s2 varchar2,s3 varchar2,s4 varchar2,s5 varchar2,s6 varchar2)
return varchar2
is
--傳一字符串取最大值
v_max varchar2(20);
begin
v_max := case when s1 is null then s1
when s2 is null then s1
when s3 is null then greatest(s1,