NULL terminated string?

RDBMS from IBM and IBM's Hierarchical DBMS and Transaction Manager (IMS DC).
Post Reply
Hemendra Singh
New Member
Posts: 2
Joined: Wed Aug 06, 2014 1:36 pm

NULL terminated string?

Post 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??
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: NULL terminated string?

Post 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.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: NULL terminated string?

Post 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.
Regards
Nic
User avatar
Akatsukami
Global Moderator
Global Moderator
Posts: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

Re: NULL terminated string?

Post 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.
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DB2 and IMS DB/DC”