SQL LEN() 函數(shù)

sql len() 函數(shù)

len() 函數(shù)返回文本字段中值的長度。

 

1. len() 語法

select len(column_name) from table_name;

mysql 中函數(shù)為 length():

select length(column_name) from table_name;

樣本數(shù)據(jù)庫

在本教程中,我們將使用 yapf 樣本數(shù)據(jù)庫。

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

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | google       | https://www.google.cm/    | 1     | usa     |
| 2  | 淘寶          | https://www.taobao.com/   | 13    | cn      |
| 3  | 碩編程      | http://www.slktour.com/  | 4689  | cn      |
| 4  | 微博          | http://weibo.com/         | 20    | cn      |
| 5  | facebook     | https://www.facebook.com/ | 3     | usa     |
|  6 | 百度         | https://www.baidu.com/    |     4 | cn      |
|  7 | stackoverflow | http://stackoverflow.com/ |     0 | ind     |
+----+---------------+---------------------------+-------+---------+

 

2. len() 范例

下面的 sql 語句從 "websites" 表中選取 "name" 和 "url" 列中值的長度:

select name, length(url) as lengthofurl from websites;

執(zhí)行結果:
+---------------+-------------+
| name          | lengthofurl |
+---------------+-------------+
| google        |    22       |
| 淘寶           |    23       |
| 碩編程       |     27      |
| 微博           |    17       |
| facebook      |    25       |
| 百度           |    23       |
| stackoverflow |    25       |
+---------------+-------------+

下一節(jié):sql round() 函數(shù)

sql 教程

相關文章
亚洲国产精品第一区二区,久久免费视频77,99V久久综合狠狠综合久久,国产免费久久九九免费视频