这里也提出了同样的问题:MySQL blob: how to get just a subset of the stored data。
但是,提供的解决方案不起作用,SUBSTRING
和MID
都无法正常使用 BLOB 数据类型。我是否错过了这个查询的内容:SELECT SUBSTRING(file, 12, 48) FROM log WHERE id=8
,子集从位置1开始,长度稍微为48。
谢谢。
答案 0 :(得分:0)
SUBSTRING
函数似乎在VARBINARY
和BLOB
上正常工作,至少在MariaDB 5.6.20:
MySQL [gps]> show create table KV \G
*************************** 1. row ***************************
Table: KV
Create Table: CREATE TABLE `KV` (
`kv_key` varbinary(767) NOT NULL,
`kv_value` longblob NOT NULL,
PRIMARY KEY (`kv_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)
MySQL [gps]> select HEX(kv_key), HEX(kv_value) from KV where kv_key > x'99' limit 10;
+--------------------------------------------------------+------------------------+
| HEX(kv_key) | HEX(kv_value) |
+--------------------------------------------------------+------------------------+
| FC0696FC1A4AD423B65465FC3D7BBBAFCBDCD8FC657A8BB203FE0F | |
| FC114A8CF4C01BD7 | 01FE589B5E0200 |
| FC114A8CF4C01BD7FCC991 | 55414200 |
| FC114AF271B994BF | 01FE589B5E0200 |
| FC114AF271B994BFFCC991 | 434F50442050696C6F7400 |
| FC1A4AD423B65465 | 01FE589B5E0200 |
| FC1A4AD423B65465FC2550FCB7D4D490FCA2E4 | |
+--------------------------------------------------------+------------------------+
10 rows in set (0.00 sec)
MySQL [gps]> select HEX(SUBSTRING(kv_key, 4, 4)), HEX(kv_value) from KV where kv_key > x'99' limit 10;
+------------------------------+------------------------+
| HEX(SUBSTRING(kv_key, 4, 4)) | HEX(kv_value) |
+------------------------------+------------------------+
| FC1A4AD4 | |
| 8CF4C01B | 01FE589B5E0200 |
| 8CF4C01B | 55414200 |
| F271B994 | 01FE589B5E0200 |
| F271B994 | 434F50442050696C6F7400 |
| D423B654 | 01FE589B5E0200 |
| D423B654 | |
+------------------------------+------------------------+
10 rows in set (0.01 sec)
MySQL [gps]> select HEX(kv_key), HEX(SUBSTRING(kv_value, 4, 4)) from KV where kv_key > x'99' limit 10;
+--------------------------------------------------------+--------------------------------+
| HEX(kv_key) | HEX(SUBSTRING(kv_value, 4, 4)) |
+--------------------------------------------------------+--------------------------------+
| FC0696FC1A4AD423B65465FC3D7BBBAFCBDCD8FC657A8BB203FE0F | |
| FC114A8CF4C01BD7 | 9B5E0200 |
| FC114A8CF4C01BD7FCC991 | 00 |
| FC114AF271B994BF | 9B5E0200 |
| FC114AF271B994BFFCC991 | 44205069 |
| FC1A4AD423B65465 | 9B5E0200 |
| FC1A4AD423B65465FC2550FCB7D4D490FCA2E4 | |
+--------------------------------------------------------+--------------------------------+
10 rows in set (0.00 sec)