Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

What is the difference between len and datalength

4 posts in General Discussion Last posting was on 2010-08-11 20:01:20.0Z
XX Posted on 2010-08-06 19:34:22.0Z
Sender: 5296.4c5c6303.1804289383@sybase.com
From: XX
Newsgroups: sybase.public.ase.general
Subject: What is the difference between len and datalength
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4c5c63be.52a9.1681692777@sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 6 Aug 2010 12:34:22 -0700
X-Trace: forums-1-dub 1281123262 10.22.241.41 (6 Aug 2010 12:34:22 -0700)
X-Original-Trace: 6 Aug 2010 12:34:22 -0700, 10.22.241.41
Lines: 9
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:29454
Article PK: 78687

I did read the specs that
len returns the mumber of chars
datalength returns the number of bytes
but do not see any difference when used in varchar or char
columns.

Anybody can explain the difference?

Thanks


Neal Stack [Sybase] Posted on 2010-08-06 20:08:34.0Z
From: "Neal Stack [Sybase]" <nstack@nospam.com>
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: sybase.public.ase.general
Subject: Re: What is the difference between len and datalength
References: <4c5c63be.52a9.1681692777@sybase.com>
In-Reply-To: <4c5c63be.52a9.1681692777@sybase.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4c5c6bc2$1@forums-1-dub>
Date: 6 Aug 2010 13:08:34 -0700
X-Trace: forums-1-dub 1281125314 10.22.241.152 (6 Aug 2010 13:08:34 -0700)
X-Original-Trace: 6 Aug 2010 13:08:34 -0700, vip152.sybase.com
Lines: 17
X-Authenticated-User: techsupp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:29455
Article PK: 78686

Hello,

If you have multi-byte data such as Chinese or Japanese, you will see a
difference:

1> select len(c1), datalength(c1) from chinese_fruit
2> go

----------- -----------
16 20
16 20
16 20
18 20

--
Regards,
Neal


"Mark A. Parsons" <iron_horse Posted on 2010-08-06 23:28:46.0Z
From: "Mark A. Parsons" <iron_horse@no_spamola.compuserve.com>
User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version: 1.0
Newsgroups: sybase.public.ase.general
Subject: Re: What is the difference between len and datalength
References: <4c5c63be.52a9.1681692777@sybase.com> <4c5c6bc2$1@forums-1-dub>
In-Reply-To: <4c5c6bc2$1@forums-1-dub>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4c5c9aae$1@forums-1-dub>
Date: 6 Aug 2010 16:28:46 -0700
X-Trace: forums-1-dub 1281137326 10.22.241.152 (6 Aug 2010 16:28:46 -0700)
X-Original-Trace: 6 Aug 2010 16:28:46 -0700, vip152.sybase.com
Lines: 36
X-Authenticated-User: TeamSybase
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:29458
Article PK: 78688

And another example:

====================
use tempdb
go

create table t1(a varchar(10), b univarchar(10))
go

insert t1 values ('test','test')
go

select len(a), datalength(a), len(b), datalength(b) from t1
go


----------- ----------- ----------- -----------
4 4 4 8

====================

Neal Stack [Sybase] wrote:
> Hello,
>
> If you have multi-byte data such as Chinese or Japanese, you will see a
> difference:
>
> 1> select len(c1), datalength(c1) from chinese_fruit
> 2> go
>
> ----------- -----------
> 16 20
> 16 20
> 16 20
> 18 20
>


XX Posted on 2010-08-11 20:01:20.0Z
Sender: 261a.4c6300d1.1804289383@sybase.com
From: XX
Newsgroups: sybase.public.ase.general
Subject: Re: What is the difference between len and datalength
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4c630190.2636.1681692777@sybase.com>
References: <4c5c9aae$1@forums-1-dub>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 11 Aug 2010 13:01:20 -0700
X-Trace: forums-1-dub 1281556880 10.22.241.41 (11 Aug 2010 13:01:20 -0700)
X-Original-Trace: 11 Aug 2010 13:01:20 -0700, 10.22.241.41
Lines: 40
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:29463
Article PK: 78694

It cleaned things up now.
Thanks

> And another example:
>
> ====================
> use tempdb
> go
>
> create table t1(a varchar(10), b univarchar(10))
> go
>
> insert t1 values ('test','test')
> go
>
> select len(a), datalength(a), len(b), datalength(b) from
> t1 go
>
>
> ----------- ----------- ----------- -----------
> 4 4 4 8
>
> ====================
>
> Neal Stack [Sybase] wrote:
> > Hello,
> >
> > If you have multi-byte data such as Chinese or Japanese,
> > you will see a difference:
> >
> > 1> select len(c1), datalength(c1) from chinese_fruit
> > 2> go
> >
> > ----------- -----------
> > 16 20
> > 16 20
> > 16 20
> > 18 20
> >