Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Datalength Function In Sql in SQL

Datalength Function In Sql in SQL

? DATALENGTH Function in SQL

The DATALENGTH() function returns the number of bytes used to store a value in a column or expression.


? Syntax

DATALENGTH(expression)
  • expression: The column or value you want to measure.


? What it Returns

  • Number of bytes used to store the data, including trailing spaces for CHAR and VARCHAR.

  • Different from LEN() which returns the number of characters (ignoring trailing spaces).


? Example (SQL Server)

SELECT DATALENGTH('Hello World') AS DataLength;  -- Returns 11 (bytes)SELECT DATALENGTH(CAST('Hello' AS VARCHAR(10))) AS DataLength;  -- Returns 5SELECT DATALENGTH(CAST('Hello' AS NVARCHAR(10))) AS DataLength; -- Returns 10 (2 bytes per character)

? Use Cases

  • To check storage size of data.

  • Useful for binary, varbinary, or string data to find actual bytes used.


If you want examples for other SQL dialects or differences between DATALENGTH() and LEN(), just ask!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql