功能简介
oracle数据库 varchar2语法样式:
LightDB 23.1版本在语法层面兼容oracle varchar2;
支持如下语法形式:
- varchar2
- varchar2(10)
- varchar2(10 byte)
- varchar2(10 char)
- varchar2(10 BYTE)
- varchar2(10 CHAR)
- varchar2(10 ByTe)
- varchar2(10 cHAr)
LightDB varchar2内部已字符来计算长度,无论在建表时指定的是byte或者char或者不指定。
用法
lightdb@postgres=# create table t1(id int, name varchar2(10));
CREATE TABLE
lightdb@postgres=# insert into t1 values(1, '你好呀,你在干什么呢');
INSERT 0 1
lightdb@postgres=# insert into t1 values(1, '你好呀,你在干什么呢?');
ERROR: input value length is 11; too long for type varchar2(10)
lightdb@postgres=# insert into t1 values(2, 'abcdefghij');
INSERT 0 1
lightdb@postgres=# insert into t1 values(2, 'abcdefghijk');
ERROR: input value length is 11; too long for type varchar2(10)
lightdb@postgres=# drop table t1;
DROP TABLE
lightdb@postgres=#
lightdb@postgres=# create table t2(id int, name varchar2(10 byte));
CREATE TABLE
lightdb@postgres=# insert into t2 values(1, '你好呀,你在干什么呢');
INSERT 0 1
lightdb@postgres=# insert into t2 values(1, '你好呀,你在干什么呢?');
ERROR: input value length is 11; too long for type varchar2(10)
lightdb@postgres=# insert into t2 values(2, 'abcdefghij');
INSERT 0 1
lightdb@postgres=# insert into t2 values(2, 'abcdefghijk');
ERROR: input value length is 11; too long for type varchar2(10)
lightdb@postgres=# drop table t2;
DROP TABLE
lightdb@postgres=#
lightdb@postgres=# create table t3(id int, name varchar2(10 char));
CREATE TABLE
lightdb@postgres=# insert into t3 values(1, '你好呀,你在干什么呢');
INSERT 0 1
lightdb@postgres=# insert into t3 values(1, '你好呀,你在干什么呢?');
ERROR: input value length is 11; too long for type varchar2(10)
lightdb@postgres=# insert into t3 values(2, 'abcdefghij');
INSERT 0 1
lightdb@postgres=# insert into t3 values(2, 'abcdefghijk');
ERROR: input value length is 11; too long for type varchar2(10)
lightdb@postgres=# drop table t3;
DROP TABLE
lightdb@postgres=#