SQL LEN() 函數(shù)


 LEN() 函數(shù)返回文本字段中值的長(zhǎng)度。

SQL LEN() 語(yǔ)法

SELECT LEN(column_name) FROM table_name;    

演示數(shù)據(jù)庫(kù)


 在本教程中,我們將使用眾所周知的 Northwind 樣本數(shù)據(jù)庫(kù)。

 下面是選自 "Customers" 表的數(shù)據(jù):

CustomerID CustomerName ContactName Address City PostalCode Country
1

Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4

Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbk?p Christina Berglund Berguvsv?gen 8 Lule? S-958 22 Sweden

SQL LEN() 實(shí)例


 下面的 SQL 語(yǔ)句從 "Customers" 表中選取 "CustomerName" 和 "Address" 列中值的長(zhǎng)度:

實(shí)例

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