varchar2(10)和varchar2(10 char)的区别

前端之家收集整理的这篇文章主要介绍了varchar2(10)和varchar2(10 char)的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

--创建测试表,一个是varchar2(5),一个是5 char
sql> create table test(cola varchar2(5),colb varchar2(5 char));

Table created

sql> desc test;
Name Type Nullable Default Comments
---- ---------------- -------- ------- --------
COLA VARCHAR2(5) Y
COLB VARCHAR2(5 CHAR) Y

--插入数据,均为5个字符,正常插入
sql> insert into test values ('abc12','abc12');

1 row inserted

sql> select * from test;

COLA COLB
----- ----------
abc12 abc12

sql> commit;

Commit complete

--插入6个字符的的报错,varchar2(5)col A 限制了

sql> insert into test values ('abc123','abc123'); insert into test values ('abc123','abc123') ORA-12899: 列 ""."TEST"."COLA" 的值太大 (实际值: 6,最大值: 5) --col b 多一个中文字符报错 sql> insert into test values ('abc12','abc12张'); insert into test values ('abc12','abc12张') ORA-12899: 列 ""."TEST"."COLB" 的值太大 (实际值: 6,最大值: 5) sql> insert into test values ('abc12','abc1张'); 2 sql> sql> insert into test values ('abc12','abc1张'); 1 row inserted sql> commit; Commit complete sql> insert into test values ('abc1张','abc1张'); insert into test values ('abc1张','abc1张') ORA-12899: 列 ""."TEST"."COLA" 的值太大 (实际值: 6,最大值: 5) sql> select * from test; 2 sql> sql> select * from test; COLA COLB ----- ---------- abc12 abc12 abc12 abc1张 sql> 原文链接:https://www.f2er.com/oracle/213193.html

猜你在找的Oracle相关文章