mysql - 当我尝试将行更新到表时,出现以下错误 :

标签 mysql

mysql> select * from GSLAB;
+--------+--------------+
| empid  | destignation |
+--------+--------------+
| GS101  | Manager      |
| GS102  | ABC          |
| GS-103 | SAS          |
| GS-104 | dsSAS        |
| GS105  | EWSAS        |
| GS106  | EWQAS        |
+--------+--------------+
6 rows in set (0.00 sec)

mysql> update GSLAB set empid= substr(empid,4,15)||substr(empid,1,2)||'-' where empid substr(empid,1,3)<>'-';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'substr(empid,1,3)<>'-'' at line 1
mysql> 

最佳答案

我使用 concat 函数而不是 concat 运算符“||”

mysql> 更新 GSLAB set empid= concat(substr(empid,1,2),'-',substr(empid,4,15)) 其中 substr(empid,1,3)<>'-';

关于mysql - 当我尝试将行更新到表时,出现以下错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43169195/

相关文章:

php - 我无法连接到数据库

php - 无法添加或更新子行,外键约束失败

php - 实时搜索无法使用 Bootstrap 4、PHP、MySQLi 和 Ajax 运行

mysql - 将 postgresql 查询转换为适用于 mysql 的查询

mysql - MySQL 的查询语法

php - MYSQL 日期时间 - PHP 转换

mysql - 使用内部连接和两个外部键连接两个表

asp.net - 使用 MySqlSessionProvider 时,什么删除过期的 session ?

mysql - Docker Run 命令并导入 MySQL

mysql - 在mysql中选择重复的ID