2015-08-03 37 views

回答

1

您可以試試這樣。選擇CONCAT('N0C',LPAD('1',5,0));

語法:SELECT CONCAT('N0C', LPAD(your_column_name,5,0)) from table_name;

SQL:SELECT CONCAT('N0C', LPAD(old_columnname_NODE,5,0)) as new_columnname_NODE from table_name;

更新SQL:update table_name set NODE = CONCAT('N0C', LPAD(old_columnname_NODE,5,0));

謝謝。

1

在這裏你可以怎麼做,

mysql> select concat(left('N0C0000',length('N0C0000')-length('1')),'1') as r; 
+---------+ 
| r  | 
+---------+ 
| N0C0001 | 
+---------+ 
1 row in set (0.00 sec) 

現在改變這個更新命令會是什麼樣子

update table_name 
set node = concat(left('N0C0000',length('N0C0000')-length(node)),node); 

下面是測試情況

mysql> select * from test ; 
+------+ 
| node | 
+------+ 
| 1 | 
| 127 | 
| 13 | 
+------+ 
3 rows in set (0.00 sec) 

mysql> update test set node = concat(left('N0C0000',length('N0C0000')-length(node)),node); 
Query OK, 3 rows affected (0.05 sec) 
Rows matched: 3 Changed: 3 Warnings: 0 

mysql> select * from test ; 
+---------+ 
| node | 
+---------+ 
| N0C0001 | 
| N0C0127 | 
| N0C0013 | 
+---------+ 
3 rows in set (0.00 sec)