Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Firebird Null guide.pdf
Скачиваний:
10
Добавлен:
23.08.2013
Размер:
78.64 Кб
Скачать

Firebird Null Guide

The correct way to test for NULL is:

...is null / ...is not null

These tests always return true or false - no messing around. Examples:

if (MyField is null) then...

select * from Pupils where PhoneNumber is not null

select * from Pupils where not (PhoneNumber is null) /* does the same as the previous example */

update Numbers set Total = A + B + C where A + B + C is not null

You could say that whereas “ = ” (when used as an equality operator) can only compare values, “ is ” tests for a state.

Setting a field or variable to NULL

Fields and variables can be set to NULL using the same syntax as for regular values:

insert into MyTable values (1, 'teststring', NULL, '8-May-2004')

update MyTable set MyField = null where YourField = -1

if (Number = 0) then MyVariable = null;

- “Wait a minute... and you said that MyField = NULL was illegal!”

That's right... for the comparison operator =” (at least in pre-2.0 versions of Firebird). But here we are talking about “=” as an assignment operator. Unfortunately, both operators have the same symbol in SQL. In assignments, whether done with “=” or with an insert list, you can treat NULL just like any value - no special syntax needed (or indeed possible).

Dealing with NULLs

This section contains some practical tips and examples that may be of use to you in your everyday dealings with NULLs.

Testing for NULL - if it matters

Quite often, you don't need to take special measures for fields or variables that may be NULL. For instance, if you do this:

select * from Customers where Town = 'Ralston'

you probably don't want to see the customers whose town is unspecified. Likewise:

if (Age >= 18) then CanVote = 'Yes'

9