Skip to Main Content
  • Questions
  • inhibit printing the value "(null) for a null column

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, mike.

Asked: December 19, 2004 - 6:05 pm UTC

Last updated: December 19, 2004 - 7:40 pm UTC

Version: 9.2.0.4

Viewed 1000+ times

You Asked

I have logged a TAR on this question,but, got nowhere.

i have written many proC programs and whenever i select a column with a null value and print it using printf, the printed value is blank.
This has always worked for me under unix.

However, on Linux, when I run the same program, nulls are printed as "(null)".

As i am outputting data as a flat file for subsequent loads, i need to have this value blank.

Other than decoding every column which may be NULL,

How do i do it under linux???


thanks
MIke

and Tom said...

it is no different under unix then linux -- what I think you are seeing is different behavior in the C runtime library.

I'd have to see your code. You need to use NULL indicators (only way to deal with NULL's in C) and do something like:


exec sql whenever sqlerror continue;
exec sql drop table t;

EXEC SQL WHENEVER SQLERROR DO die();

exec sql create table t ( x varchar2(10), y varchar2(20) );
exec sql insert into t values ( 'Not null', 'hello world' );
exec sql insert into t values ( 'Is null', null );
exec sql commit;

exec sql declare C cursor for select x, y from t;
exec sql open c;
for( ;; )
{
exec sql whenever notfound do break;
exec sql fetch c into :x:x_ind, :y:y_ind;
printf( "%s %s\n", (x_ind?"":x), (y_ind?"":y) );
}
exec sql whenever notfound continue;
exec sql close c;
exit(0);
}


See how in the printf we look at the indicator variables to see if the string is "NULL" or not null.

If you have not been doing this logic in the past, you have been what is known as "extremely lucky" not to have seg-faulted. Sounds like you are printing out a NULL pointer and your printf runtime is printing the word (null) -- I've seen that behavior with various C runtimes.


that program, when run, will print:

[tkyte@localhost t]$ ./t
connecting
connected
Not null hello world
Is null
[tkyte@localhost t]$


So -- use NULL indicators and check them -- there is no other way, I've a feeling you have been extraordinarily lucky -- but you might find you legacy code's behavior changes with a libc patch or anything like that!


Is this answer out of date? If it is, please let us know via a Comment