Oracle 判斷字串為''還是Null

來源:互聯網
上載者:User

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'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.