Reputation: 280
I want to insert
a value into a table using a value of SUBSTR(data, 71, 2)
.
However if data isn't long enough then I want to input null
.
Upvotes: 0
Views: 47
Reputation: 521389
You may use a CASE
expression here:
CASE WHEN LENGTH(data) >= 73
THEN SUBSTR(data, 71, 2)
ELSE NULL END
This would be part of your larger insert statement, which you did not reveal to us.
Edit:
Calling SUBSTR
on a column with a starting position which is out of bounds will already return NULL
. However, if the starting position is within bounds and the length exceeds the length of the string, then only the available remainder of the string will be returned. Hence, the following call to SUBSTR
will return world
:
SUBSTR('hello world', 7, 30)
Upvotes: 3