Page 1 of 1

NULL terminated string?

Posted: Tue Jan 19, 2016 3:19 pm
by Hemendra Singh
Hi,

What is a NULL terminated string? I looked at this wiki article Null-terminated string :
In computer programming, a null-terminated string is a character string stored as an array containing the characters and terminated with a null character ('\0', called NUL in ASCII). Alternative names are C string, which refers to the C programming language and ASCIIZ (note that C strings do not imply the use of ASCII).

The length of a C string is found by searching for the (first) NUL byte. This can be slow as it takes O(n) (linear time) with respect to the string length. It also means that a NUL cannot be inside the string, as the only NUL is the one marking the end.
But how can it be applied to DB2 for zOS??

Re: NULL terminated string?

Posted: Tue Jan 19, 2016 4:31 pm
by William Collins
Why would you want to apply it to DB2 for z/OS? If you are storing "null-terminated strings", it is just part of the data.

Re: NULL terminated string?

Posted: Tue Jan 19, 2016 6:02 pm
by nicc
You would only need to worry about null-terminated strings if you are coding on the PC/Unix platforms. These do not have the concept of records. Data to them is a stream of bytes and as any character can be in a string then you need to know when the string ends. The C designers chose the null character (\0) but this means that your null cannot easily be incorporated into a string. But you do not have to worry about such things on the mainframe where the traditional languages deal in records and know what a string is.

Re: NULL terminated string?

Posted: Tue Jan 19, 2016 7:15 pm
by Akatsukami
Note that if you are embedding SQL in a C or PL/I program where NUL-terminated strings do exist, DB2 will accept them but convert them to standard VARCHAR (prefixed with a halfword length) for storage, and will convert the VARCHAR data to NUL-terminated strings, if necessary, when they are SELECTed or FETCHed.