null與substr

wisdomone1發表於2013-01-22
C:\Users\123>sqlplus scott/system
SQL*Plus: Release 11.2.0.1.0 Production on Tue Jan 22 16:53:44 2013
Copyright (c) 1982, 2010, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table t_substr(a varchar2(10));
Table created.
SQL> insert into t_substr values(null);
1 row created.
SQL> insert into t_substr values('zxy');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t_substr;
A
--------------------
zxy
 
SQL> select substr(a,1,2) from t_substr;
SUBSTR(A,1,2)
----------------
zx
 
SQL> select substr(null,1,2) from dual;

S
-
SQL> select substr(null,1,2) from t_substr;

S
-
 
 
小結:
          1,如變數值為null,substr執行不會報錯,可以正常處理
 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-753051/,如需轉載,請註明出處,否則將追究法律責任。

相關文章