问题描述
OceanBase 数据库 MySQL 模式语句中带有 Update + Order by 报错信息如下。
ERROR 5868 (HY000): Incorrect usage of UPDATE and ORDER BY
相关表结构与测试数据。
创建测试表 A、B。
obclient [mysql]> create table A (id int , name varchar(100)); Query OK, 0 rows affected (0.069 sec)obclient [mysql]> create table B (id int , name varchar(100)); Query OK, 0 rows affected (0.027 sec)向表 A、B 插入测试数据。
obclient [mysql]> insert into A values (1,'A'); Query OK, 1 row affected (0.030 sec)obclient [mysql]> insert into B values (1,'B'); Query OK, 1 row affected (0.004 sec)执行更新与排序。
obclient [mysql]> update A a left join B b on a.id=b.id set a.name=b.name where a.id=1 order by a.id;输出结果如下。
ERROR 5868 (HY000): Incorrect usage of UPDATE and ORDER BY
问题原因
兼容性问题,OceanBase 数据库不支持在 Update 语句中使用 Order By。
适用版本
OceanBase 数据库 V3.x 版本。
解决方法
修改 SQL 语句绕过,比如改成如下。
obclient [db_mysql]> update A a left join B b on a.id=b.id set a.name=b.name where a.id=1;
Query OK, 1 row affected (0.736 sec)
Rows matched: 1 Changed: 1 Warnings: 0