Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type Conversion in Informix 4GL

Tags:

informix

4gl

I want to convert a variable of type VARCHAR to INTEGER and vice versa (i.e. from INTEGER type to VARCHAR) in Informix 4GL.

like image 371
Abhi421987 Avatar asked Apr 18 '26 17:04

Abhi421987


1 Answers

DEFINE v VARCHAR(20)
DEFINE i INTEGER

LET v = "12345"
LET i = v
DISPLAY "i = ", i, "; v = ", v

LET i = 123456
LET v = i
DISPLAY "i = ", i, "; v = ", v

Easy, huh?

You run into problems if the string can't be converted to a number (run time errors, etc).

In essence, I4GL will automatically convert between types if it is possible, only generating an error if it is impossible. Some conversions are impossible. For example, I don't think you'd be able to convert a DECIMAL or INTEGER into an INTERVAL YEAR TO MONTH.

like image 90
Jonathan Leffler Avatar answered Apr 20 '26 07:04

Jonathan Leffler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!