Nulls Indicate Absence of Value (162)

tsinglee發表於2007-11-08

A null is the absence of a value in a column of a row. Nulls indicate missing,
unknown, or inapplicable data. A null should not be used to imply any other value,
such as zero. A column allows nulls unless a NOT NULL or PRIMARY KEY integrity
constraint has been defined for the column, in which case no row can be inserted
without a value for that column.
Nulls are stored in the database if they fall between columns with data values. In these
cases they require 1 byte to store the length of the column (zero).
Trailing nulls in a row require no storage because a new row header signals that the
remaining columns in the previous row are null. For example, if the last three columns
of a table are null, no information is stored for those columns. In tables with many
columns, the columns more likely to contain nulls should be defined last to conserve
disk space.
Most comparisons between nulls and other values are by definition neither true nor
false, but unknown. To identify nulls in SQL, use the IS NULL predicate. Use the SQL
function NVL to convert nulls to non-null values.
Nulls are not indexed, except when the cluster key column value is null or the index is
a bitmap index.

空值
1. 空值表示一行的某列無值 . 空值的含義是資料缺失 , 未知 ,或N/A .空值不等同於其他任何值,如0 .
2. 當一個空值在一行中位於有資料值的兩列之間時 , 此列在資料庫中需要佔用 1 位元組的空間來儲存其列長(0).
3. 而當一個空值位於行尾時無需佔用儲存空間 , 因為新一行的行頭就標誌著前一行未儲存的欄位均為空 .
4. Oracle 中規定空值和其他任何值的比較結果既非真也非假 , 而是未知 . 如需在 SQL 中判斷空值 , 應該使用謂詞IS NULL .
使用者可以使用 SQL 函式 NVL 將空值轉換為非空值.
5. 空值不會被加入索引 , 但有兩種情況例外:其一是為空值的列屬於簇鍵,其二是索引為點陣圖索引

[@more@]

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

相關文章