【IT168 服务器学院】对sybase处理字符串的一些体会
1)字符串中即有双引号也有单引号,用双引号引用时对于字符串中的双引号用双引号转义,单引号不用管;用单引号引用时对于字符串中的单引号用单号转义,双引号不用管。
举例如下:
表 table_1
字段 name char(10)
值 a
select name from table_1 where name=''a'' 和 select name from table_1 where name=“a” 都一样
值 ''a
select name from table_1 where name="''a"
值 "a
select name from table_1 where name=''"a''
值 "''a
select name from table_1 where name="""''a" 和 select name from table_1 where name=''"''''a'' 都一样
2)关于datalength()函数
datelength 函数只对于可变长的字符串有效,varchar(),char()无效,要删除后导空格, datelength(rtrim(char()))
举例如下:
create table test(a1 varchar(40),a2 char(40))
insert test values(''123'',''123'')
select datalength(a1),datalength(a2) from test
返回3和40
select datalength(a1),datalength(rtirm(a2)) from test
返回3和3
3)varchar和char到底多长
用sybase的对varchar和char只能255肯定都有意见,到12.5以后有所不同了。两方面,页面大小不再是单一2K;即使页面设为2K,varchar和char都可以突破255,但不能超过2K。
举例如下:
create table test(a1 varchar(300),a2 char(300))
insert test values(replicate(''a'',300),replicate(''a'',300))
select * from test