以散分为目的,以解决问题为原则......

tigi 2002-05-29 08:37:53
我想知道关于char和varchar的数据类型的区别,以及它们在系统中所占用的资源。谢谢!在什么情况下使用varchar?是否应尽可能少的使用varchar?
...全文
91 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuzhanwen 2002-05-29
  • 打赏
  • 举报
回复

                         
                         
     *        *    *     
     *   *    * *******  
*********** ****   *     
     *        *    *     
  *******     * *******  
   *    *     **    *    
   *   *    *** *******  
    * *       * *   *    
     *        *  *  *    
   ** **      *     *    
***     *** ***   ***    

qwen 2002-05-29
  • 打赏
  • 举报
回复
学习
水煮蛙 2002-05-29
  • 打赏
  • 举报
回复
TO:zhanwei(詹维) ( ) 什么时候开个辅导班嘛!我报名,顺便骗点资料:)
对了上次你说pb自带的多表更新的列子在哪里!pb自带的列子怎么看,看什么,还望指教!
snowarea 2002-05-29
  • 打赏
  • 举报
回复
所说是正确了 fibbery(飞)
ddtid 2002-05-29
  • 打赏
  • 举报
回复
我来晚了
想说得别人都说完了,郁闷:(
ljl_7880 2002-05-29
  • 打赏
  • 举报
回复
这么长,还是英文的???
呵呵
zhanwei 2002-05-29
  • 打赏
  • 举报
回复
Character data types
Function
For storing strings of letters, numbers and symbols.
Description
Adaptive Server Anywhere treats CHAR, VARCHAR, and LONG VARCHAR columns all as the same type. Values up to 254 characters are stored as short strings, with a preceding length byte. Any values that are longer than 255 bytes are considered long strings. Characters after the 255th byte are stored separate from the row containing the long string value.
There are several functions (see SQL Functions ) that will ignore the part of any string past the 255th character. They are soundex, similar, and all of the date functions. Also, any arithmetic involving the conversion of a long string to a number will work on only the first 255 characters. It would be extremely unusual to run in to one of these limitations.
All other functions and all other operators work with the full length of long strings.
Character sets and code pages
Character data is placed in the database using the exact binary representation that is passed from the application. This usually means that character data is stored in the database with the binary representation of the current code page. The code page is the character set representation used by IBM-compatible personal computers. You can find documentation about code pages in the documentation for your operating system.
Most code pages are the same for the first 128 characters. If you use special characters from the top half of the code page (accented international language characters), you must be careful with your databases. In particular, if you copy the database to a machine that uses a different code page, those special characters will be retrieved from the database using the original code page representation. With the new code page, they will appear on the screen to be the wrong characters.
This problem also appears if you have two clients using the same multi-user server, but run with different code pages. Data inserted or updated by one client may appear incorrect to the other.
This problem also shows up if a database is used across platforms. PowerBuilder and many other Windows applications insert data into the database in the standard ANSI character set. If non-Windows applications attempt to use this data, they will not properly display or update the extended characters.
This problem is quite complex. If any of your applications use the extended characters in the upper half of the code page, make sure that all clients and all machines using the database use the same or a compatible code page.
Notes
Data type lengths of less than one are not allowed.
Compatibility
稵he CHARACTER (n) alternative for CHAR is not supported in Adaptive Server Enterprise.
稟daptive Server Anywhere does not support the NCHAR and NVARCHAR data types provided by Adaptive Server Enterprise.
CHAR data type [Character]
Function
Character data of maximum length max-length bytes.
Syntax
{ CHAR | CHARACTER } [ ( max-length ) ]
Usage
The default value of max-length is 1.
For strings up to 254 bytes in length, the storage requirement is the number of bytes in the string plus one additional byte. For longer strings, there is more overhead.
Strings of multi-byte characters can be held as the CHAR data type, but max-length is in bytes, not characters.
Parameters
max-length The maximum length in bytes of the string. The maximum size allowed is 32,767.
Standards and compatibility
稴QL/92 Compatible with SQL/92.
稴ybase Compatible with Adaptive Server Enterprise. In Adaptive Server Enterprise, the storage requirements for CHAR data types is always max-length. The maximum max-length for ASE is 255.
稯ther database systems In many other database-management systems, unlike Adaptive Server Anywhere,CHAR data types require max-length bytes of storage, regardless of the length of the actual string.
See also
CHARACTER VARYING data type
LONG VARCHAR data type
CHARACTER VARYING data type [Character]
Function
Same as CHAR.
Syntax
{ VARCHAR | CHARACTER VARYING } [ ( max-length ) ]
Usage
The default value of max-length is 1.
For strings up to 254 bytes in length, the storage requirements are the number of bytes in the string plus one additional byte. For longer strings, there is more overhead.
Strings of multi-byte characters can be held as the CHAR data type, but it is important to note that max-length is in bytes, not characters.
Parameters
max-length The maximum length of the string, in bytes. The maximum size allowed is 32,767.
Standards and compatibility
稴QL/92 Compatible with SQL/92.
稴ybase Compatible with Adaptive Server Enterprise. The maximum max-length for Adaptive Server Enterprise is 255.
See also
CHAR data type
LONG VARCHAR data type
LONG VARCHAR data type [Character]
Function
Arbitrary length character data.
Syntax
LONG VARCHAR
Usage
Arbitrary length strings. The maximum size is limited by the maximum size of the database file (currently 2 gigabytes).
In addition to the length of the string itself, there is some additional overhead for storage.
Standards and compatibility
稴QL/92 Vendor extension.
稴ybase Not supported in Adaptive Server Enterprise.
See also
CHAR data type
CHARACTER VARYING data type
TEXT data type [Character]
Function
This is a domain. It is implemented as a LONG VARCHAR allowing NULL.
Syntax
TEXT
Usage
Arbitrary length strings. The usage is as for LONG VARCHAR.
Standards and compatibility
稴QL/92 Vendor extension.
稴ybase Compatible with Adaptive Server Enterprise.
See also
LONG VARCHAR data type
xiaoxianhe 2002-05-29
  • 打赏
  • 举报
回复
又学一招!高兴中!
sydeng 2002-05-29
  • 打赏
  • 举报
回复
vchar是变长字符数据,其长度不超过8k;
char 是定长字符数据,其长度不超过8k.
jackygan 2002-05-29
  • 打赏
  • 举报
回复
呵呵, zhanwei(詹维) 说得好。
zhanwei 2002-05-29
  • 打赏
  • 举报
回复
to: fibbery(飞)
客气客气!
fibbery 2002-05-29
  • 打赏
  • 举报
回复
to 詹维兄:
在你哪我总能学到东西!呵呵!
Flying_Hawk 2002-05-29
  • 打赏
  • 举报
回复
楼上说的不错!
zhanwei 2002-05-29
  • 打赏
  • 举报
回复
1、如: fibbery(飞)
2、char 检索速度较varchar快,列为码时、常用检索依据时使用,。

vchar 255字符以下,不用char时!
fibbery 2002-05-29
  • 打赏
  • 举报
回复
字符数不定的时候用vchar,
比如:地址,邮件……
fibbery 2002-05-29
  • 打赏
  • 举报
回复
char(10),如果不够10个字符,会用空格补位;
vchar(10),标示最多可以有10个字符,不够10个不补!
wnchg 2002-05-29
  • 打赏
  • 举报
回复
zergwang(神游) 说的好
Kuye2002yx 2002-05-29
  • 打赏
  • 举报
回复
大家都说得棒极了,收藏了
左格 2002-05-29
  • 打赏
  • 举报
回复
varchar和char的存储空间是不一样的,varchar是可变的存储空间,char是不可变的存储空间。这种区别你使用length函数就可以发现。
一般对于较长的无法确定其输入内容的字段采用varchar,增加空间的利用率;而对于另外一些较短的可以确定其字段内容的字段一般采用char,增加检索的速度。

1,077

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧