這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)oracle和MySQL關(guān)于關(guān)聯(lián)更新的差別有哪些,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比扎賚諾爾網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式扎賚諾爾網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋扎賚諾爾地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。
mysql報錯 ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause
今天網(wǎng)站有些數(shù)據(jù)出現(xiàn)異常,需要把出現(xiàn)異常的數(shù)據(jù)更正,具體操作是把一個表中的publish_date字段關(guān)聯(lián)更新成同一個表中的up_date字段,我們的數(shù)據(jù)是先存到oracle,然后通過到mysql中的,所有異常數(shù)據(jù)存在于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');
然后對應(yīng)著改寫成mysql相應(yīng)表和相應(yīng)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,把要更新的幾列數(shù)據(jù)查詢出來做為一個第三方表,然后篩選更新。
2,新建一個臨時表保存查詢出的數(shù)據(jù),然后篩選更新。最后刪除臨時表。
具體如下:
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);
如下是關(guān)于關(guān)聯(lián)更新的一些實驗:
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中是不能關(guān)聯(lián)更新同一個表的,但是oracle中可以;實驗4和5可以知道oracle中不能使用update a,b set a.=b.之類的語句;實驗3可以知道,mysql可以使用update a,b set a.=b.之類的語句來關(guān)聯(lián)更新表;
上述就是小編為大家分享的oracle和mysql關(guān)于關(guān)聯(lián)更新的差別有哪些了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
本文名稱:oracle和mysql關(guān)于關(guān)聯(lián)更新的差別有哪些
文章出自:http://chinadenli.net/article4/ggpdie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、云服務(wù)器、外貿(mào)建站、軟件開發(fā)、網(wǎng)站改版、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)