Varchar2 size how to decide?

When you execute a complicate store procedure, maybe it will execute a long time, maybe you want to change some logic,

And retry, but when you recreate or replace, you will get error, the object is locked.

So just try this.

https://zhefeng.wordpress.com/2010/05/25/cant-compile-a-stored-procedure-when-its-locked/

I read that oversizing a varchar2 column in a table doesn‘t affect storage space, but does effect query performance.

http://hrivera99.blogspot.com/2008/05/why-is-varchar2-oversizing-bad.html

Varchar2(4000 byte)

set serveroutput on;

declare

v_test varchar2(9) ;

v_test2 varchar2(3 char);

begin

v_test := ‘人民隊‘;

v_test2 :=‘人民隊‘;

DBMS_OUTPUT.PUT_LINE(‘*‘ || v_test || ‘*‘);

DBMS_OUTPUT.PUT_LINE(‘*‘ || v_test2 || ‘*‘);

end;

--Error report -

--ORA-06502: PL/SQL: numeric or value error: character string buffer too small

set serveroutput on;

declare

v_test varchar2(9 byte) ;

v_test2 varchar2(3 char);

begin

v_test := ‘人民隊‘;

v_test2 :=‘人民隊‘;

DBMS_OUTPUT.PUT_LINE(‘*‘ || length( v_test) || ‘*‘);---return char count

DBMS_OUTPUT.PUT_LINE(‘*‘ || lengthb( v_test2) || ‘*‘);--return bytes count

end;

--3

--9

<http://stackoverflow.com/questions/2241238/why-does-oracle-varchar2-have-a-mandatory-size-as-a-definition-parameter>

  • The database uses the length of a variable when allocating memory for PL/SQL collections. As that memory comes out of the PGA supersizing the variable declaration can lead to programs failing because the server has run out of memory.
  • Supersized columns create problems for compound indexes. The following is on a database with 8K block
  • columns sizes are a form of error checking. If the column is supposed to be ten characters long and some autonomic process is trying to load a thousand characters then something is wrong. 

Datatype


Description


Column Length / Default Values


CHAR

[(size [BYTE | CHAR])]


Fixed-length character data of length size bytes or characters.


Fixed for every row in the table (with trailing blanks); maximum size is 2000 bytes per row, default size is 1 byte per row. When neither BYTE nor CHAR is specified, the setting of NLS_LENGTH_SEMANTICS at the time of column creation determines which is used. Consider the character set (single-byte or multibyte) before setting size.


VARCHAR2

(size [BYTE | CHAR])


Variable-length character data, with maximum length size bytes or characters. BYTE or CHAR indicates that the column has byte or character semantics, respectively. A size must be specified.


Variable for each row, up to 4000 bytes per row. When neither BYTE nor CHAR is specified, the setting ofNLS_LENGTH_SEMANTICS at the time of column creation determines which is used. Consider the character set (single-byte or multibyte) before setting size.


NCHAR [(size)]


Fixed-length Unicode character data of length size characters. The number of bytes is twice this number for the AL16UTF16 encoding and 3 times this number for the UTF8 encoding.)


Fixed for every row in the table (with trailing blanks). The upper limit is 2000 bytes per row. Default sizeis 1 character.


NVARCHAR2 (size)


Variable-length Unicode character data of maximum length size characters. The number of bytes may be up to 2 times size for a the AL16UTF16 encoding and 3 times this number for the UTF8 encoding. A sizemust be specified.


Variable for each row. The upper limit is 4000 bytes per row


DATE


Fixed-length date and time data, ranging from Jan. 1, 4712 B.C.E. to Dec. 31, 9999 C.E.


Fixed at 7 bytes for each row in the table. Default format is a string (such as DD-MON-RR) specified by theNLS_DATE_FORMAT parameter.

Pasted from <http://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_ty.htm>

The lengths of CHAR and VARCHAR2 columns can be specified as either bytes or characters.

The lengths of NCHAR and NVARCHAR2 columns are always specified in characters, making them ideal for storing Unicode data, where a character might consist of multiple bytes.

Pasted from <http://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_ty.htm>

时间: 2024-10-10 02:49:39

Varchar2 size how to decide?的相关文章

varchar和varchar2的区别

--varchar,varchar2 联系:1.varchar/varchar2用于存储可变长度的字符串比如varchar(20),存入字符串'abc',则数据库中该字段只占3个字节,而不是20个字节2.size 的最大值是 4000,而最小值是 1,其值表示字节数,比如varchar(20)表示最大可以存放20个字节的内容 区别:1.varchar2把所有字符都占两字节处理(一般情况下),varchar只对汉字和全角等字符占两字节,数字,英文字符等都是一个字节:2.VARCHAR2把空串等同于

Oracle CHAR,VARCHAR,VARCHAR2,nvarchar类型的区别与使用(转载)

一 varchar,varchar2,nvarchar,nvarchar2 四个类型都属于变长字符类型, varchar和varchar2的区别在与后者把所有字符都占两字节,前者只对汉字和全角等字符占两字节,都是非 Unicode 字符数据,可以定义的最大长度为4000字节. nvarchar和nvarchar2的区别和上面一样,   与上面区别在于是根据Unicode   标准所进行的定义的类型(长度定义的是字符数,而不是字节数),通常用于支持多国语言类似系统的定义,可以定义的最大长度为400

oracle中varchar,varchar2,nvarchar,nvarchar2的区别

--varchar,varchar2 联系: 1.varchar/varchar2用于存储可变长度的字符串 比如varchar(20),存入字符串'abc',则数据库中该字段只占3个字节,而不是20个字节 2.size 的最大值是 4000,而最小值是 1,其值表示字节数,比如 varchar(20)表示最大可以存放20个字节的内容 区别: 1.varchar2把所有字符都占两字节处理(一般情况下),varchar只对汉字和全角等字符占两字节,数字,英文字符等都是一个字节: 2.VARCHAR2

Oracle varchar2或char类型的byte和char的区别

Oracle定义字符串类型VARCHAR2和CHAR指定长度的用法如下: varchar2(<SIZE> <BYTE|CHAR>) <SIZE>是介于1~4000之间的一个数,表示最多占用4000字节的存储空间.char(<SIZE> <BYTE|CHAR>) <SIZE>是介于1~2000之间的一个数,表示最多占用2000字节的存储空间.那其中的BYTE和CHAR有什么区别呢BYTE,用字节指定:VARCHAR2(10 BYTE).

Oracle中varchar,varchar2,nvarchar,nvarchar2的区别及其它数据类型描述

--varchar,varchar2 联系: 1.varchar/varchar2用于存储可变长度的字符串 比如varchar(20),存入字符串'abc',则数据库中该字段只占3个字节,而不是20个字节 2.size 的最大值是 4000,而最小值是 1,其值表示字节数,比如 varchar(20)表示最大可以存放20个字节的内容 区别: 1.varchar2把所有字符都占两字节处理(一般情况下),varchar只对汉字和全角等字符占两字节,数字,英文字符等都是一个字节: 2.VARCHAR2

『ORACLE』 创建表(11g)

CREATE TABLE语句 create table [schema.] 表名 (column datatype [DEFAULT expr][, ...]); 在插入的过程中,为列指定一个默认值 ...hire_date DATE DEFAULT SYSDATE,... 默认值必须满足列的数据类型定义 create table hire_dates (id number(8),hire_date date default sysdate); create table dept (deptno

Oracle 语言基础

1,基本 select 语句 select  *|{[distinct] column|expression [alias],...} from  table; distinct 删除重复行 2,过滤和排序 where 子句紧随 from子句 字符和日期要包含单引号中 默认日期格式是DD-MON-RR; 比较运算 = ,>, >=, <, <=,<>不等于也可以是(!=)   还有between and  ,in(set)  ,like(%代表零个或者多个字符,_代表一

SQL 基础之DDL语句创建和管理表(十四)

数据库对象 Object 描述 表 基本的数据存储集合,由行和列组成 View 从一张表或多张表中抽出的 逻辑上相关的数据集合 序列 生成规律的数值 index 索引 提高查询性能 Synonym 别名 给对象起的别名 表名和列名注意事项: 必须以字母开头 必须在 1–30 个字符之间 必须只能包含 A–Z, a–z, 0–9, _, $, 和 # 必须不能和用户定义的其他对象重名 必须不能是Oracle的保留字 CREATE TABLE  语句 必须具有: – CREATE TABLE 权限

Datatypes translation between Oracle and SQL Server

Datatypes translation between Oracle and SQL Server part 1: character, binary strings Datatypes translation is one of the most important things you need to consider when migrate your application from one database to the other. This is an article in t