sql 如何使用SQL确定字符串的长度?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 如何使用SQL确定字符串的长度?相关的知识,希望对你有一定的参考价值。

---------------SQL Server---------------------------------------
select 

'I love you' as phrase,
len('I love you') as phrase_length,
len(' I love you ') as phrase_length2,
datalength(' I love you ') as phrase_length3

phrase     |phrase_length |phrase_length2 |phrase_length3 |
-----------|--------------|---------------|---------------|
I love you |10            |11             |12             |

--------------MySQL----------------------------------------------
select 

'I love you' as phrase,
length('I love you') as phrase_length

phrase     |phrase_length |
-----------|--------------|
I love you |10            |

--------------PostgreSQL-----------------------------------------
select 

'I love you' as phrase,
length('I love you') as phrase_length


phrase     |phrase_length 
-----------|--------------
I love you |10            

以上是关于sql 如何使用SQL确定字符串的长度?的主要内容,如果未能解决你的问题,请参考以下文章