Monday 29 July 2013

SQL: How to Cast an Integer to String in DB2



A CAST function can be used to convert one data type to another in DB2.
For example:
SELECT 100, LPAD(CAST(100 as VARCHAR(5)), 5, 'X') AS CONVERTED FROM SYSIBM.SYSDUMMY1;
Output
1 CONVERTED
100 XX100


In the example the LPAD function is used to show that the converted value is of type varchar and not integer.



REFERENCES:
Casting between data types

No comments:

Post a Comment