Oracle 判断字符串为''还是Null

59 篇文章 0 订阅
oracle 判断varchar2类型是不是为空'' ,用什么判断符

VV_LIST:='DSSSFDFDSFDS';
IF(VV_LIST <>'')THEN
  DBMS_OUTPUT.PUT_LINE('PPPPPPPPPPPPPPPPP');
  ELSE
  DBMS_OUTPUT.PUT_LINE('BBBBBBBBBBBBBBBBBBBBBBBB');
  END IF;

结果却打印了BBBBBBBBBBBBBBBBBBBBBBBB


IF ('' IS NULL) THEN
  dbms_output.put_line(''''' is null');
  END IF;
输出:'' is null

这说明,在oracle pl/sql里,把''当成null处理了


Oracle中的空应该用的是null,非空就是not null
for example:

SQL code
   
   
SQL > set serveroutput on SQL > declare 2 str varchar ( 20 ): = ' helloworld ' ; 3 begin 4 if str <> '' then 5 dbms_output.put_line( ' is not null ' ); 6 else 7 dbms_output.put_line( ' is null ' ); 8 end if ; 9 end ; 10 / is null PL / SQL procedure successfully completed.

SQL code
   
   
SQL > set serveroutput on SQL > declare 2 str varchar ( 20 ): = ' helloworld ' ; 3 begin 4 if str is not null then 5 dbms_output.put_line( ' is not null ' ); 6 else 7 dbms_output.put_line( ' is null ' ); 8 end if ; 9 end ; 10 / is not null PL / SQL procedure successfully completed.
所以可以这么做:


select   

st.koyu_zaisan_no
,st.koyu_zaisan_edaban
,st.shutoku_nendo  --?異動年度
,st.shutokubi          --?異動日
,st.kaikei
,'会計名'                 --?
,st.shukanka          --?
,'KANJYO_KAMOKU_MEISHO'  --?
,'金額'
,'err_no'                 --?
,'err_naiyo'            --?
,'0' csv_type          --?

from SHISAN_TAB st
where  trim(nvl(st.chiku_cd,'')) || 'A' ='A'
or  trim(nvl(st.chimoku,'')) || 'B' ='B'



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值