In my database there is a field in type VARCHAR (let's name in field1), in some cases, I want to find special record and edit the value of field1, my query must be able to read the current value of field1 and add special string like ".a" at the end of it. I guess the query must be something like this:
UPDATE TableName SET field1 = CurrentValue +'a' WHERE field1 = CurrentValue ;
but its not complete, and there is error. Would you help开发者_JAVA百科 me?!!
You are looking for SET field1 = CONCAT(field1,'a')
The procedure you said you got an error for works for me:
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> create table test.Files (Name text) select 'MyFile' Name;
Query OK, 1 row affected (0.10 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> delimiter //
mysql> CREATE PROCEDURE test.Rename (CurrentName Text) BEGIN UPDATE test.Files SET Name = CONCAT(Name , 'a') WHERE Name = CurrentName; END//
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call test.Rename('MyFile');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test.Files;
+---------+
| Name |
+---------+
| MyFilea |
+---------+
1 row in set (0.00 sec)
精彩评论