Language basics / Data types |
The VARCHAR data type is a variable-length character string data type, with a maximum size.
VARCHAR [ ( size [,reserve] ) ]
VARCHAR variables are initialized to NULL in functions, modules and globals.
The size can be expressed in bytes or characters, depending on the length semantics used in programs.
MAIN DEFINE vc VARCHAR(10) LET vc = "abc " -- two trailing blanks DISPLAY "[", vc ,"]" -- displays [abc ] IF vc == "abc" THEN -- this is TRUE DISPLAY "equals" END IF END MAIN
When you insert character data from VARCHAR variables into VARCHAR columns in a database table, the trailing blanks are kept. Likewise, when you fetch VARCHAR column values into VARCHAR variables, trailing blanks are kept.
MAIN DEFINE vc VARCHAR(10) DATABASE test1 CREATE TABLE table1 ( k INT, x VARCHAR(10) ) LET vc = "abc " -- two trailing blanks INSERT INTO table1 VALUES ( 1, vc ) SELECT x INTO vc FROM table1 WHERE k = 1 DISPLAY "[", vc ,"]" -- displays [abc ] END MAIN
In SQL statements, the behavior of the comparison operators when using VARCHAR values differs from one database to the other. IBM® Informix® is ignoring trailing blanks, but most other databases take trailing blanks of VARCHAR values into account.