Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a null field problem

Status
Not open for further replies.

vicky2003

Programmer
May 27, 2003
22
CA
Hi,
I'm a new Web page maker.I met a simple but boring question.
When I access data from database,I found if some fiels are null, it will throw a exception. Could anyone tell me:

1. how to judge if a number field in Oracle is null or not?
2. how to judge if a string field is null or not?
3. how to set a field(string,number) value is null ?
Tks,
 
HI,
Normally accessing data that contains a NULL for 1 or more fields in a record will not cause an exception ( at least Oracle won't care ) - So it must be what you are doing with the retreived data that throws the exception.

So your application code needs to test for NULLs this way ( not real code since I do not know what language you are using)
Code:
If <fieldname> IS NULL then ....
( works for number and string types)
Be careful of blank strings instead of NULLs they are different - a string of 1 space character ( like &quot; &quot;) is not a NULL string even tho' it contains no real information so to test blanks I usually use
Code:
If <stringfieldvalue> < '0' then

To create a NULL value for a field ( either character or number) use a standard assignment:
Code:
<fieldname> = NULL

hth,
[profile]

 
You have to be a bit careful because the default type of NULL is string and this can sometimes cause confusion to a Web application which is expecting a number or date. It's best to explicitly type it, as in:

to_number(NULL)
to_date(NULL)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top