开发者

Does Sybase support string types that it doesn't right trim?

The accepted answer to this question claims that using a cha开发者_如何转开发r column will preserve all filling spaces in a string in Sybase, but that is not the behavior I am seeing (unless I'm mistaken about what 'filling spaces' means). For example, when I run the following script:

create table #check_strings
(
    value char(20) null
)

insert into #check_strings values (null)
insert into #check_strings values ('')
insert into #check_strings values (' ')
insert into #check_strings values ('     ')
insert into #check_strings values ('blah')
insert into #check_strings values ('blah ')
insert into #check_strings values ('blah    ')
insert into #check_strings values ('    blah    ')

select value, len(value) from #check_strings

I get the following output:

[NULL]            - [NULL]
[single space]    - 1
[single space]    - 1
[single space]    - 1
blah              - 4
blah              - 4
blah              - 4
[four spaces]blah - 8

Is there any way to get Sybase to not strip off trailing spaces? Additionally, is there any way to get it to save an empty string as an empty string, and not as a single space?

I'm using Sybase 15.5.


To have fixed length on char columns, you must use the not null attribute.

For variable length columns, use varchar or char with a null attribute.

Then to measure the real data size use the datalength function not the len function nor the charlength function.


See http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.sqlug/html/sqlug/sqlug208.htm

"When you create a char, unichar, or nchar column that allows nulls, Adaptive Server converts it to a varchar, univarchar, or nvarchar column and uses the storage rules for those datatypes."

Please, check not null column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜