Oracle横向求最大值(二)

本文介绍了如何在Oracle中处理空值并获取字段的最大值。提供了两种方法,一种是直接在SQL查询中使用CASE语句进行空值判断,另一种是创建自定义函数`max_value`来实现相同功能。这两种方法都可以有效地处理多个字段的空值情况,并返回最大值。
摘要由CSDN通过智能技术生成

在上次基础上,添加空值判断:

一.直接判断

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,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值