使用 BLOB 类型声明来获取列长度的 MySQL 查询
为此,请使用 MySQL 的 LENGTH() 函数。我们首先创建一个表。我们已将列的类型声明为 BLOB −
mysql> create table DemoTable ( Title blob ); Query OK, 0 rows affected (0.57 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('This is a MySQL tutorial'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Java is an object oriented programming language'); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable values('C is a procedural language'); Query OK, 1 row affected (0.20 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+-------------------------------------------------+ | Title | +-------------------------------------------------+ | This is a MySQL tutorial | | Java is an object oriented programming language | | C is a procedural language | +-------------------------------------------------+ 3 rows in set (0.00 sec)
以下是使用 LENGTH() 方法获取用 BLOB 类型声明的列长度的查询 −
mysql> select length(Title) from DemoTable;
这将产生以下输出 −
+---------------+ | length(Title) | +---------------+ | 24 | | 47 | | 26 | +---------------+ 3 rows in set (0.00 sec)
广告