Skip to content

Instantly share code, notes, and snippets.

@ateneva
Last active May 27, 2018 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateneva/905cffae481670a00e1a615db5eef72b to your computer and use it in GitHub Desktop.
Save ateneva/905cffae481670a00e1a615db5eef72b to your computer and use it in GitHub Desktop.
How do I determine the length of a string with 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment