Skip to content

SQL LEN() 函数 ​


LEN() 函数返回文本字段中值的长度。

SQL LEN() 语法 ​

sql
SELECT LEN(column_name) FROM table_name;

演示数据库 ​


在本教程中,我们将使用众所周知的 Northwind 样本数据库。

下面是选自 "Customers" 表的数据:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

SQL LEN() 实例 ​


下面的 SQL 语句从 "Customers" 表中选取 "CustomerName" 和 "Address" 列中值的长度:

实例 ​

SELECT CustomerName,LEN(Address) as LengthOfAddress
FROM Customers;