os: centos 7.4
db: postgresql 11.5
db: oracle 11.2.0.4

oracle varchar2(n) 表示 n 个字节

postgresql varchar(n) 表示 n 个字符

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
#
# su - postgres
Last login: Sat Oct 26 22:55:25 CST 2019 on pts/0
$
$ psql -c "select version();"version
---------------------------------------------------------------------------------------------------------PostgreSQL 11.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)
# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
#
# su - oracle
Last login: Tue Jan 21 03:40:05 CST 2020 on pts/0
$ sqlplus / as sysdba;SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 3 10:29:09 2020Copyright (c) 1982, 2013, Oracle.  All rights reserved.Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing optionsSQL> set lines 300;
SQL> set pages 300;
SQL>
SQL> select * from v$version;BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0  Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - ProductionSQL> 

oracle varchar2(n)

SQL> set lines 300;
set pages 300;SQL> create table tmp_t0(name varchar2(2));Table created.SQL> insert into tmp_t0(name) values('a'); 1 row created.SQL> insert into tmp_t0(name) values('aa');1 row created.
SQL> insert into tmp_t0(name) values('aaa');
insert into tmp_t0(name) values('aaa')*
ERROR at line 1:
ORA-12899: value too large for column "SCOTT2"."TMP_T0"."NAME" (actual: 3,maximum: 2)SQL> insert into tmp_t2(name) values('我');
insert into tmp_t2(name) values('我')*
ERROR at line 1:
ORA-12899: value too large for column "SCOTT2"."TMP_T0"."NAME" (actual: 3,maximum: 2)
SQL> select name,length(name),lengthb(name) from tmp_t0;NA LENGTH(NAME) LENGTHB(NAME)
-- ------------ -------------a        2         2
aa        2         2

postgresql varchar(n)

postgres=# create table tmp_t0(name varchar(2));
CREATE TABLE
postgres=#
postgres=# insert into tmp_t0(name) values('a');
INSERT 0 1
postgres=# insert into tmp_t0(name) values('aa');
INSERT 0 1
postgres=# insert into tmp_t0(name) values('aaa');
ERROR:  value too long for type character varying(2)
postgres=#
postgres=# insert into tmp_t0(name) values('我');
INSERT 0 1
postgres=# insert into tmp_t0(name) values('我我');
INSERT 0 1
postgres=# insert into tmp_t0(name) values('我我我');
ERROR:  value too long for type character varying(2)
postgres=# 
postgres=# select name,char_length(name),octet_length(name),bit_length(name) from tmp_t0;name | char_length | octet_length | bit_length
------+-------------+--------------+------------a    |           1 |            1 |          8aa   |           2 |            2 |         16我   |           1 |            3 |         24我我 |           2 |            6 |         48
(4 rows)

char_length 字符长度
octet_length 字节长度
bit_length bit长度(一个字节8个bit)

oracle varchar2(n) 与 postgresql varchar(n) 的区别相关推荐

  1. 在Oracle中CHAR,NCHAR,VARCHAR,VARCHAR2,NVARCHAR2这五种类型的区别

    [在Oracle中CHAR,NCHAR,VARCHAR,VARCHAR2,NVARCHAR2这五种类型的区别 ] 1.CHAR(size)和VARCHAR(size)的区别  CHAR为定长的字段,最 ...

  2. Oracle 实时复制到 PostgreSQL或EnterpriseDB

    Oracle GoldenGate支持种类繁多的数据库的同步,功能非常强大. 从mysql, oracle同步到PostgreSQL的又一利器. 开源的从mysql,oracle同步到PostgreS ...

  3. SQL全方位攻略:5. SQL “方言”大比拼:Oracle、MySQL、PostgreSQL限制检索行数语法详解(分页查询)

    系列文章目录 SQL全方位攻略:1.数据库介绍 SQL全方位攻略:2.SQL介绍 SQL全方位攻略:3.SQL标准 SQL全方位攻略:4. 标准SQL和SQL"方言" 文章目录 系 ...

  4. oracle varchar2改成大字段类型clob,读取大字段内容

    oracle varchar2(4000)改成大字段类型clob,如果需要改成大字段的varchar2列有内容,不能直接用 alter table med_generic modify option0 ...

  5. oracle varchar2() 占几个字母,Oracle number date varchar2字段类型占用空间大小

    oracledate类型占用存储空间是7个字节oraclevarchar2类型占用存储空间是每个字符占用一个字节oraclenumber类型占用存储空间是几个字节number最少占用两个字节, ora ...

  6. Oracle varchar2 4000

    关于oracle varchar2 官方文档的描述 VARCHAR2 Data TypeThe VARCHAR2 data type specifies a variable-length chara ...

  7. 开源数据同步备份工具(MySQL、Oracle、SqlServer、PostgreSQL)

    真正的大师,永远都怀着一颗学徒的心! 一.项目简介 今天说的是一个开源数据同步备份工具,他支持mysql.oracle.kafka.PostgreSQL.sqlserver等 二.实现功能 数据同步与 ...

  8. ORACLE VARCHAR2最大长度是4000?还是32767?

     ORACLE VARCHAR2最大长度问题 url:http://www.cnblogs.com/kerrycode/p/3833746.html 2014-07-09 15:53 by 潇湘隐 ...

  9. mysql和oracle模糊查询_oracle模糊查询mysql的区别

    oracle与使用mysql的区别 1.Like模糊查询有字符串拼接 所有用 str1||str2 拼接的字符串都要改成CONCAT(str1,str2) '%'||#{zbmc}||'%'改成CON ...

  10. varchar和Nvarchar区别 ----转载

    varchar和Nvarchar区别 Unicode字符集就是为了解决字符集这种不兼容的问题而产生的,它所有的字符都用两个字节表示,即英文字符也是用两个字节表示 如果还为了这个纠结,就直接看看后面的解 ...

最新文章

  1. mysql 5.7 full_MySQL5.7默认打开ONLY_FULL_GROUP_BY 解决方案
  2. 如何扩大控件的触控响应区域
  3. celery 学习笔记 01-介绍
  4. 创建与合并分支-git入门教程
  5. GraphViz :1 安装和简单使用
  6. 【Python基础】Pandas参数设置的八个小技巧
  7. caxa画图怎么倒角_16个底部含圆弧倒角的宽槽编程案例
  8. matlab常用函数——数学函数
  9. 了解Entity Framework中事务处理
  10. 除了默认的docker0网桥,启动Docker服务怎么指定使用的网桥
  11. open source Swift, Objective-C and the next 20 years of development
  12. Flask实现登录功能【附完整Demo】
  13. 关于注册表、组策略、设置灰色联想
  14. 计算机科学的方法论有三个过程,计算机科学与技方法论3.ppt
  15. 树莓派4b控制机械手臂_STM32与树莓派(上位机)交互控制机械臂
  16. 字节跳动 Go RPC 框架 KiteX 性能优化实践
  17. anaconda安装软件包
  18. 电容三点式LC振荡器电路组成及工作原理简述
  19. 微信编辑器都有什么功能?
  20. 在日本,虚拟人都能赚百万美元了

热门文章

  1. 单片机与一般微型计算机相比具有哪些特点,单片机原理与接口技术习题答案
  2. 基于组件技术的电子海图显示系统开发方法
  3. 爱立信面试前的GitHub项目如何上传
  4. 计算机专业认识实习目的,计算机专业实习目的与意义
  5. 为什么打印机打印照片模糊_我用打印机打印照片为什么不清楚?应该怎样调 – 手机爱问...
  6. java每日学习回忆录
  7. 史上最全的Linux常用命令汇总(超全面!超详细!)收藏这一篇就够了!
  8. 一拳超人手游显示服务器断开,一拳超人最强之男游戏无法登陆怎么办 解决方案一览...
  9. ffmpeg学习日记11-使用ffmpeg将视频格式转换为视频编码h264格式
  10. VB6 TCP通讯服务端、客户端源码