Search code examples
sqlviewdb2barcode

How to concatenate a tab in a DB2 view field?


I've been attempting to create a Db2 (the database is hosted on an IBM i, running 7.3) view in which one of the fields (a character/char field) is constructed by concatenating several different pieces of data together. The catch is that between each of these fields of data, there needs to be a tab present which is used for delimiting the fields in a DataMatrix barcode.

The following link is an ASCII and EBCDIC character set that I'm using as a reference. I'm using the hexadecimal code for a horizontal tab as follows to try and concatenate the tabs in the character field that I'm constructing(e.g.):

select 'data1' || X'09' || 'data2' from 
sysibm.sysdummy1;

Unfortunately, the only thing present, which results from the hexadecimal code (X'09') appears to be one single space, as follows:

Result set:    
data1 data2

When I use the resulting field in the view to generate a 2D barcode, there are actually no spaces at all delimiting the fields (seen after scanning said barcode). What's the trick to actually getting a tab to be rendered in a Db2 view field? Is there a different code or function I should be using? I've also tried using char(05) and char(09), but to no avail. In addition, I've tried casting the hexadecimal code as a character, as follows, but with no success:

select 'data1' || cast(X'09' as CHAR) || 'data2' from 
sysibm.sysdummy1;

Any thoughts or ideas would be much appreciated!


Solution

  • Try x'05' instead.

    If you copy-past the following char sequence ("a" + "\tab" + "b") from some text editor, you get the result as described:

    values hex('a   b');
    
    |00001 |
    |------|
    |810582|