Type Conversion Functions in DataStage - Data Warehousing

Character Generation and Conversion

Date and Time Conversion

Numeric Validation Functions

DataStage Type Conversion Functions

In DataStage, type conversion functions enable you to convert one data type into another during the transformation of data. This article provides an overview of various built-in DataStage type conversion functions and examples of their usage.

Built-In Type Conversion Functions

Example: Converting a Character String to a Date using TO_DATE()

        <Transformation>
            <Input>
                <ColumnList>
                    <Column name="date" type="VARCHAR"/>
                </ColumnList>
            </Input>
            <Output>
                <ColumnList>
                    <Column name="converted_date" type="DATE"/>
                </ColumnList>
            </Output>
            <TransformationTask>
                <SQL>
                    SELECT date AS "date", TO_DATE(date, 'YYYY-MM-DD') AS "converted_date" FROM input_table;
                </SQL>
            </TransformationTask>
        </Transformation>
    

Example: Converting a Date to a Character String using TO_CHAR()

        <Transformation>
            <Input>
                <ColumnList>
                    <Column name="date" type="DATE"/>
                </ColumnList>
            </Input>
            <Output>
                <ColumnList>
                    <Column name="converted_date_str" type="VARCHAR"/>
                </ColumnList>
            </Output>
            <TransformationTask>
                <SQL>
                    SELECT date AS "date", TO_CHAR(date, 'YYYY-MM-DD') AS "converted_date_str" FROM input_table;
                </SQL>
            </TransformationTask>
        </Transformation>
    

Conclusion

DataStage provides several built-in type conversion functions to convert data types during the transformation process. Understanding and mastering these functions will aid in creating efficient ETL processes.