char 和 varchar的区别
varchar variablelength 变长
char fixedlength 固定长度
char定义的时候分配内存而varchar动态分配内存
下面一个例子明确的说明了这两个的区别
SQL> DECLARE
c CHAR() := ;
v VARCHAR() := ;
BEGIN
dbms_outputput_line(c is [||LENGTH(c)||]);
dbms_outputput_line(v is [||LENGTH(v)||]);
v := v || ;
dbms_outputput_line(v is [||LENGTH(v)||]); END;
/
c is []
v is []
v is []
PL/SQL 过程已成功完成
输出的结果显示CHAR类型变量在定义的时候分配内存分配的内存也可能超过变量定义的大小VARCHAR类型变量动态分配内存根据设置的变量的大小
下面的例子也说明这一点
SQL> DECLARE
c CHAR() := ;
v VARCHAR() := ;
var CHAR := ; Implicitly sized at byte
var CHAR() := ; Explicitly sized at byte
var CHAR( BYTE) := ; Explicitly sized at byte
var CHAR( CHAR) := ; Explicitly sized at character
BEGIN
dbms_outputput_line(c is [||LENGTH(c)||]);
dbms_outputput_line(v is [||LENGTH(v)||]);
dbms_outputput_line(var is [||LENGTH(var)||]);
dbms_outputput_line(var is [||LENGTH(var)||]);
dbms_outputput_line(var is [||LENGTH(var)||]);
dbms_outputput_line(var is [||LENGTH(var)||]);
v := v || ;
dbms_outputput_line(v is [||LENGTH(v)||]); END;
/
c is []
v is []
var is []
var is []
var is []
var is []
v is []
character 和 char的区别
CHARACTER类型是CHAR的subtypeCHARACTER类型和它的基类优相同的大小在CHAR和CHARACTER数据类型之间隐式转换以下是一个subtype的定义
SUBTYPE subtype_name IS base_type[(maximum_size [BYTE | CHAR])] [NOT NULL];
应用例子:
SQL> DECLARE
SUBTYPE code IS CHAR( CHAR);
c CHAR( CHAR) := A;
d CODE;
BEGIN
d := c;
END;
/
PL/SQL 过程已成功完成