A script-enabled browser is required for this page to function properly.

PL/SQL conversion utility: CHAR replaced by VARCHAR2

In PL/SQL V1, the datatypes CHAR and VARCHAR2 could be used interchangeably. In versions after V1, the CHAR datatype is right padded with blanks.

In PL/SQL V1, this statement:

var1 CHAR(10) := ‘hello’;

. . .is equal to ‘hello’.

In versions after V1, however, this statement resolves to a total of ten characters:

‘hello     ’

To preserve the V1 behavior of CHAR variables, the conversion utility replaces all CHAR(n) declarations with the equivalent VARCHAR2(n) statement. In the preceding example, var1 becomes VARCHAR2(10).

The conversion utility also replaces all VARCHAR statements with the equivalent VARCHAR2 expression.

Restrictions

Versions after PL/SQL V1 require a length for all VARCHAR2 variables. If a length is already specified for a CHAR datatype, the conversion utility uses that length when replacing the declaration with VARCHAR2. For example:

var1 CHAR(10);

. . .is converted to:

var1 VARCHAR2(10);

When the converter detects a CHAR or VARCHAR2 statement without a string length, it suggests a length of one character. For example:

var2 CHAR;

. . .is converted to:

var2 VARCHAR2(1);

Similarly,

var3 VARCHAR2;

. . .is converted to:

var3 VARCHAR2(1);

If you do not supply a length for a VARCHAR2 declaration, the compiler generates this error message:

ERROR 215: String length constraint must be in range (1..32767)

See also

About the PL/SQL conversion utility