开发有个同事,某个表的dtucode列的数据需要修改下,设计到几千条数据,手工作很要命。
dtucode的类型为varchar(20),需要把以0030开头,并且后四位转换为16进制。
00301100
00301101
00301102
实现方式:
SELECT CONCAT('0030',HEX(CONVERT((SUBSTRING(dtucode,5)),SIGNED ))),
HEX(CONVERT((SUBSTRING(dtucode,5)),SIGNED )),SUBSTRING(dtucode,5),dtucode
FROM table1 WHERE LENGTH(dtucode) = 8 AND dtucode LIKE '0030%';
结果:
003044c
003044d
003044e
查询convert用法:
CONVERT(expr,type), CONVERT(expr USING transcoding_name)
The CONVERT() and CAST() functions take a value of one type and produce a value of another type.
The type can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
阅读(11702) | 评论(0) | 转发(0) |