Varchar2 size how to decide?

本文探讨了复杂存储过程执行过程中遇到的对象锁定问题及其解决方案,并深入解析了 Oracle 数据库中 VARCHAR2 类型的不同定义方式及其对内存分配、查询性能的影响。

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>

 

转载于:https://www.cnblogs.com/huaxiaoyao/p/4253510.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值