我想把一列数据前全部加0,如何实现啊? 如题!!不要叫我手动添加啊,呵呵 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MYSQL?列是什么类型?update tt set f1=concat('0',f1) mysql> create table test_num(id int(6) zerofill);Query OK, 0 rows affected (0.20 sec)mysql> insert into test_num values(203);Query OK, 1 row affected (0.02 sec)mysql> select * from test_num;+--------+| id |+--------+| 000203 |+--------+1 row in set (0.00 sec)mysql> update tt set f1=concat('0',f1)这样不行? update chinapostalcode set 区号 = concat('0',区号)我是这样写的,可是不行,提示说Data too long for column '' at row 1,单引号里乱码了 请仔细看我的回由此,使用:id int(6) zerofill 类型即可。mysql> create table test_num(id int(6) zerofill);Query OK, 0 rows affected (0.20 sec)mysql> insert into test_num values(203);Query OK, 1 row affected (0.02 sec)mysql> select * from test_num;+--------+| id |+--------+| 000203 |+--------+1 row in set (0.00 sec)mysql> (不要高估你的汉语表达能力或者我的汉语理解能力) 建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。 参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html 1. 你的 create table xxx .. 语句 2. 你的 insert into xxx ... 语句 3. 结果是什么样,(并给以简单的算法描述) 4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL) 这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。 mysql> create table t1(id int(6));Query OK, 0 rows affected (0.08 sec)mysql> insert into t1 values(1003);Query OK, 1 row affected (0.01 sec)mysql> select * from t1;+------+| id |+------+| 1003 | +------+1 row in set (0.00 sec)mysql> alter table t1 modify id int(6) zerofill;Query OK, 1 row affected (0.04 sec)Records: 1 Duplicates: 0 Warnings: 0mysql> select * from t1;+--------+| id |+--------+| 001003 | +--------+1 row in set (0.00 sec)mysql> 一开始不行,我之后把varchar长度改设为5后可以了 错误信息:lost connection to mysql server during query MySql中遇到一个很诡异的问题 show status和show variables有何区别啊? 交叉连接之疑问,在线求解答ing PostgreSQL性能问题 MYSQL不支持视图? 请教:关于 MySQL 和 MySQL JDBC 的问题。 linux下的mysql应用问题 jsp怎么同时更新两个表的内容 mysql与SQLSERVER的时间戳对比 检测MySql数据库的工具,大家一块讨论讨论 mysql 存储过程 注释 还原
update tt set f1=
concat('0',f1)
Query OK, 0 rows affected (0.20 sec)mysql> insert into test_num values(203);
Query OK, 1 row affected (0.02 sec)mysql> select * from test_num;
+--------+
| id |
+--------+
| 000203 |
+--------+
1 row in set (0.00 sec)mysql>
这样不行?
我是这样写的,可是不行,提示说Data too long for column '' at row 1,单引号里乱码了
请仔细看我的回由此,使用:id int(6) zerofill 类型即可。mysql> create table test_num(id int(6) zerofill);
Query OK, 0 rows affected (0.20 sec)mysql> insert into test_num values(203);
Query OK, 1 row affected (0.02 sec)mysql> select * from test_num;
+--------+
| id |
+--------+
| 000203 |
+--------+
1 row in set (0.00 sec)mysql>
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
Query OK, 0 rows affected (0.08 sec)mysql> insert into t1 values(1003);
Query OK, 1 row affected (0.01 sec)mysql> select * from t1;
+------+
| id |
+------+
| 1003 |
+------+
1 row in set (0.00 sec)
mysql> alter table t1 modify id int(6) zerofill;
Query OK, 1 row affected (0.04 sec)
Records: 1 Duplicates: 0 Warnings: 0mysql> select * from t1;
+--------+
| id |
+--------+
| 001003 |
+--------+
1 row in set (0.00 sec)mysql>