Skip to main content
Skip table of contents

tryCast

This procedure attempts to cast a value to the specific type and returns NULL instead of an error when this is not possible. If the original value is NULL, the returned value will also be NULL.

Parameters

ParameterDescription
originalValueOriginal value as an object
targetTypeTarget type name as string; mandatory

Attributes

Attribute

Type

Description

newValue

object

 Value cast to the new type

Examples

1. Valid integer value as an integer; returns a value:

SQL
CALL UTILS.tryCast(
    originalValue => '123',
    targetType => 'integer'
);; 

2. Invalid decimal value as a decimal; returns NULL:

SQL
CALL UTILS.tryCast(
    originalValue => 'abc',
    targetType => 'decimal'
);; 

3. Valid decimal value as an integer; returns NULL:

SQL
CALL UTILS.tryCast(
    originalValue => '10.25',
    targetType => 'integer'
);; 

Auto-parsing is available for these strings:

date:         
yyyy-MM-dd

timestamp:
yyyy-MM-dd
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd HH:mm:ss.S
yyyy-MM-ddTHH:mm:ss
yyyy-MM-ddTHH:mm:ss.S

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.