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
Parameter | Description |
---|---|
originalValue | Original value as an object |
targetType | Target type name as string; mandatory |
Attributes
Attribute | Type | Description |
---|---|---|
| object | Value cast to the new type |
Examples
1. Valid integer value as an integer; returns a value:
CALL UTILS.tryCast(
originalValue => '123',
targetType => 'integer'
);;
2. Invalid decimal value as a decimal; returns NULL
:
CALL UTILS.tryCast(
originalValue => 'abc',
targetType => 'decimal'
);;
3. Valid decimal value as an integer; returns NULL
:
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