What is a NULL Value?
Some columns cannot have a meaningful value in every row.
DB2 uses a special value indicator, the null value, to stand for an unknown or missing value.
A null value is a special value that DB2 interprets to mean that no data is present.
A NULL value is different from a zero value or a field that contains spaces.
A field with a NULL value is one that has been left blank during record creation.
How Null Values created?
If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field.
Then, the field will be saved with a NULL value.
If you do not specify otherwise,DB2 allows any column to contain null values.
Users can create rows in the table without providing a value for the column.
How to prevent Null Values?
Using the NOT NULL clause enables you to disallow null values in the column.
Primary keys must be defined as NOT NULL.
How to Test for NULL Values?
IS NULL and IS NOT NULL operators is used to test for NULL values.
O que é um valor NULL?
Algumas colunas não podem ter um valor significativo em todas as linhas.
O DB2 usa um indicador de valor especial, o valor nulo, para representar um valor desconhecido ou ausente.
Um valor nulo é um valor especial que o DB2 interpreta para significar que nenhum dado está presente.
Um valor NULL é diferente de um valor zero ou de um campo que contém espaços.
Um campo com um valor NULL é aquele que foi deixado em branco durante a criação do registro.
Como valores nulos são criados?
Se um campo em uma tabela for opcional, é possível inserir um novo registro ou atualizar um registro sem adicionar um valor a este campo.
Em seguida, o campo será salvo com um valor NULL.
Se você não especificar o contrário, o DB2 permite que qualquer coluna contenha valores nulos.
Os usuários podem criar linhas na tabela sem fornecer um valor para a coluna.
Como prevenir valores nulos?
O uso da cláusula NOT NULL permite que você não permita valores nulos na coluna.
As chaves primárias devem ser definidas como NOT NULL.
Como testar valores NULL?
Os operadores IS NULL e IS NOT NULL são usados ??para testar os valores NULL.
Syntax - Sintaxe: IS NULL
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
|
Syntax - Sintaxe: IS NOT NULL
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
|
DB2 Database - Banco de dados DB2:
Below is a selection from the "Product" table in the DB2 database:
Abaixo está uma seleção da tabela "Produto" no banco de dados DB2:
| ProductID | ProductDesc | Category | SRP | QtyOnHand | TotalValue |
| 7001 | Mouse | Accessories | 75.00 | | |
| 7002 | Harddrive | | 65.00 | 20 | 1,300 |
| 7003 | Keyboard | Accessories | 36.00 | 33 | 1,118.00 |
| 7004 | Ram | Components | 23.50 | 16 | 376.00 |
| 7005 | Honda | Bikes | 1,200 | | |
| 7006 | Pen | | 7.45 | 10 | 74.50 |
Example 1 - Exemplo 1:
The following SQL lists all ProductID with a NULL value in the "Category" field.
O seguinte SQL lista todos os ProductID com um valor NULL no campo "Categoria".
SELECT ProductID
FROM Product
WHERE Category IS NULL;
|
Result - Resultado:
Example 2 - Exemplo 2:
The following SQL lists all ProductID with a value in the "Category" field.
SELECT ProductID
FROM Product
WHERE Category IS NOT NULL;
|
Result - Resultado:
ProductID
7001
7003
7004
7005
|
Veja também
|