SQL LEN() 函數
sql len() 函數
len() 函數返回文本字段中值的長度。
1. len() 語法
select len(column_name) from table_name;
mysql 中函數為 length():
select length(column_name) from table_name;
樣本數據庫
在本教程中,我們將使用 yapf 樣本數據庫。
下面是選自 "websites" 表的數據:
+----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+--------------+---------------------------+-------+---------+ | 1 | google | https://www.google.cm/ | 1 | usa | | 2 | 淘寶 | https://www.taobao.com/ | 13 | cn | | 3 | 碩編程 | http://www.090948.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; 執行結果: +---------------+-------------+ | name | lengthofurl | +---------------+-------------+ | google | 22 | | 淘寶 | 23 | | 碩編程 | 27 | | 微博 | 17 | | facebook | 25 | | 百度 | 23 | | stackoverflow | 25 | +---------------+-------------+
相關文章
- SQL 教程
- SQL SELECT 語句
- SQL AND OR 運算符
- SQL ORDER BY 關鍵字
- SQL UPDATE 語句
- SQL DELETE 語句
- SQL SELECT TOP, LIMIT, ROWNUM 子句
- SQL IN 操作符
- SQL BETWEEN 操作符
- SQL INNER JOIN 關鍵字
- SQL RIGHT JOIN 關鍵字
- SQL SELECT INTO 語句
- SQL INSERT INTO SELECT 語句
- SQL CREATE TABLE 語句
- SQL 約束(Constraints)
- SQL NOT NULL 約束
- SQL PRIMARY KEY 約束
- SQL GROUP BY 語句
- SQL HAVING 子句
- SQL NULL 值