zoukankan      html  css  js  c++  java
  • 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>

     

    Looking for a job working at Home about MSBI
  • 相关阅读:
    Python 规范
    Hql
    Python
    IIS 日志分析
    NHibernate 知识点整理
    微软开放了.NET 4.5.1的源代码
    自定义消息编码绑定实现
    使用自定义绑定
    WCF安全:通过 扩展实现用户名密码认证
    WCF 几种错误
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/4253510.html
Copyright © 2011-2022 走看看