千家信息网

oracle和mysql关于关联更新的差别有哪些

发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,这期内容当中小编将会给大家带来有关oracle和mysql关于关联更新的差别有哪些,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。mysql报错 ERROR 1093
千家信息网最后更新 2025年02月02日oracle和mysql关于关联更新的差别有哪些

这期内容当中小编将会给大家带来有关oracle和mysql关于关联更新的差别有哪些,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

mysql报错 ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause

今天网站有些数据出现异常,需要把出现异常的数据更正,具体操作是把一个表中的publish_date字段关联更新成同一个表中的up_date字段,我们的数据是先存到oracle,然后通过到mysql中的,所有异常数据存在于oracle和mysql。

首先在oracle中更正:

SQL>update infoservice.t_publish_zbxx a set a.publish_date=(select b.up_date from infoservice.t_publish_zbxx b where a.record_id=b.record_id) where a.publish_date>to_date('2017-10-15','yyyy-mm-dd');

然后对应着改写成mysql相应表和相应sql,居然报错。。。。

mysql> update v_publish_info a set a.publish_date=(select b.up_date from v_publish_info b where a.id=b.id) where a.publish_date>'2017-07-15';

ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause

解决办法:

mysql> update v_publish_info a,v_publish_info b set a.publish_date=b.up_date where a.id=b.id and a.publish_date>'2017-07-15';

或者

1,把要更新的几列数据查询出来做为一个第三方表,然后筛选更新。

2,新建一个临时表保存查询出的数据,然后筛选更新。最后删除临时表。

具体如下:

create table liuwenhe.publish_date_temp as select id ,publish_date,up_date from info.v_publish_info where publish_date>'2017-07-15';

update info.v_publish_info a set a.publish_date=(select b.up_date from liuwenhe.publish_date_temp b where a.id=b.id) where a.publish_date>'2017-07-15';

为了防止匹配不上,更新为空的问题,可以加上exists条件;

update info.v_publish_info a set a.publish_date=(select b.up_date from liuwenhe.publish_date_temp b where a.id=b.id) where a.publish_date>'2017-07-15' and exists (select b.up_date from liuwenhe.publish_date_temp b where a.id=b.id);

如下是关于关联更新的一些实验:

mysql:

1.成功

mysql> update liuwenhe.publish_date_20170715 a set a.publish_date=(select b.up_date from info.v_publish_info b where a.id=b.id) where a.publish_date>'2017-07-15' and exists (select b.up_date from info.v_publish_info b where a.id=b.id );

Query OK, 0 rows affected (0.00 sec)

Rows matched: 0 Changed: 0 Warnings: 0

2.失败

mysql> update liuwenhe.publish_date_20170715 a set a.publish_date=(select b.up_date from liuwenhe.publish_date_20170715 b where a.id=b.id) where a.publish_date>'2017-07-15';

ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause

3.成功

mysql> update liuwenhe.publish_date_20170715 a,liuwenhe.publish_date_20170715 b set a.publish_date=b.in_date where a.id=b.id and a.publish_date>'2017-07-15';

Query OK, 0 rows affected (0.01 sec)

Rows matched: 0 Changed: 0 Warnings: 0

oracle:

4.失败

SQL> update liuwenhe.top_80 a,infoservice.t_member_info b set a.login_id=b.login_id where a.member_id=b.record_id;

update liuwenhe.top_80 a,infoservice.t_member_info b set a.login_id=b.login_id where a.member_id=b.record_id

ERROR at line 1:

ORA-00971: missing SET keyword

5.失败:

SQL> update liuwenhe.top_80 a,liuwenhe.top_80 b set a.login_id=b.login_id where a.member_id=b.member_id;

update liuwenhe.top_80 a,liuwenhe.top_80 b set a.login_id=b.login_id where a.member_id=b.member_id

ERROR at line 1:

ORA-00971: missing SET keyword

6.成功

SQL>update liuwenhe.top_80 a set a.login_id=(select b.login_id from infoservice.t_member_info b where a.member_id=b.record_id);

通过实验1和2比较可以知道,mysql中是不能关联更新同一个表的,但是oracle中可以;实验4和5可以知道oracle中不能使用update a,b set a.=b.之类的语句;实验3可以知道,mysql可以使用update a,b set a.=b.之类的语句来关联更新表;

上述就是小编为大家分享的oracle和mysql关于关联更新的差别有哪些了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。

更新 关联 数据 实验 成功 差别 内容 字段 语句 分析 查询 专业 中小 内容丰富 办法 就是 数据查询 文章 更多 条件 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 python常驻服务器 发票数据库异常如何解决 国家网络安全宣传周 宣讲 能管理服务器的软件 DB2数据库账号查看 澳洲十大网络安全专业 数据库判断当天是星期几 登录日本亚马逊用哪个云服务器好 崇明区本地网络技术采购信息 硬盘里数据库储存的分区出现坏道 五个跟网络技术有关的职业 延庆区网络技术服务清单 互联网科技公司20周年庆 网络安全 云南地名 计算机网络技术在线考试 网络安全宣传主题短句 淄博市网络安全支撑 关于学校网络安全的简报 类目关联商品数据库设计 获取用户填写的表单数据库 兰山灿天网络技术有限公司 关于网络安全的一篇作文 三国志战略版无法获取服务器 高校里的网络安全 网络安全法自什么起实施行 对等网络技术 青浦区综合软件开发协议 云南视频会议服务器厂家 3.2硬盘服务器需要多大电源 数据更新日志是用什么数据库
0