SQL data types can be directly used in PL/SQL. However, the maximum length of some variables is slightly different from that in SQL.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Note
For more information about SQL data types, see Built-in data types.
The following table lists the data types whose maximum lengths are different in PL/SQL and SQL:
| Data type | Maximum length in PL/SQL | Maximum length in SQL |
|---|---|---|
| VARCHAR2 | 32,767 bytes | 4,000 bytes |
| NVARCHAR2 | 32,767 bytes | 4,000 bytes |
| BLOB | 48 M | (4 GB - 1) * database_block_size |
| CLOB | 48 M | (4 GB - 1) * database_block_size |
If the assigned value exceeds the defined length of a variable, an exception will be thrown.
obclient> DECLARE
mychar VARCHAR2(3 CHAR);
BEGIN
mychar := 'abc ';
END;
/
OBE-06502: PL/SQL: numeric or value error
For string-type objects, you can use the RTRIM() function to remove trailing spaces, as shown in the following example:
obclient> DECLARE
mychar VARCHAR2(3 CHAR);
BEGIN
mychar := rtrim('abc ');
END;
/
Query OK, 0 rows affected
