首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

nvl,空时的推断和取值

Oracle/PLSQL中的一个函数。   格式为:   NVL( string1, replace_with)   功能:假设string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值,假设两个參数的都为NULL ,则返回NULL。   注意事项:string1和replace_with必须为同一数据类型,除非显示的使用TO_CHAR函数。   例:NVL(TO_CHAR(numeric_column), ‘some string’) 当中numeric_column代指某个数字类型的值。   例:nvl(yanlei777,0) > 0   NVL(yanlei777, 0) 的意思是 假设 yanlei777 是NULL, 则取 0值   通过查询获得某个字段的合计值,假设这个值为null将给出一个预设的默认值   比如:   select nvl(sum(t.dwxhl),1)   from tb_jhde t   就表示假设sum(t.dwxhl) = NULL 就返回 1   还有一个有关的实用方法   declare i integer   select nvl(sum(t.dwxhl),1) into i from tb_jhde t where zydm=-1这样就能够把获得的合计值存储到变量   i中,假设查询的值为null就把它的值设置为默认的1   orcale中:   select nvl(rulescore,0) from zwjc_graderule where rulecode=’FWTD’;   假设记录中不存在rulecode =’FWTD’的数据.则查不出数据.   select nvl(rulescore,0) into rule_score from zwjc_graderule where rulecode=’FWTD’;会报查不到数据的错   select nvl(sum(rulescore),0) from zwjc_graderule where rulecode=’FWTD’;   假设记录中不存在rulecode =’FWTD’的数据.还是能够得到一行列名为nvl(rulescore,0),值为0的数据.   select nvl(sum(rulescore),0) into rule_score from zwjc_graderule where rulecode=’FWTD’; 不会报错

02
领券