Oracle資料更改後出錯的解決方案_oracle

來源:互聯網
上載者:User

在使用Oracle的過程中我們給系統建立了兩個使用者:com和comtest。前者存放的是正式庫資料,後者存放的測試庫資料。它們都有一個taw_rm_user表,存放了使用該系統的使用者基本資料,於是就是把其中的password欄位全部改成了123456。

DMP備份檔案建立後,經過一段時間建立了幾個新的使用者,並且有些舊的使用者的其他資訊也已經更改了。但是需要把舊使用者的密碼恢複到從前,直接把備份檔案中的taw_rm_user表匯入com使用者下是肯定不行的。經過分析後,得到了一個解決方案。大致思路是:

1. 將測試庫的taw_rm_user表用CREATE TABLE AS語句導到一個臨時的備份表中(測試庫中的使用者表也不能亂改);
2. 再將taw_rm_user表刪除;
3. 然後將DMP備份檔案的taw_rm_user表用IMP命令匯入到comtest下;
4. 再自己編寫一個PL/SQL程式塊,通過使用遊標迴圈,將這個新匯入的表中的password欄位更新到com.taw_rm_user表的對應記錄中。(注意,這裡只更新對應記錄,對新加入的使用者記錄不作任何修改);
5. 再將之前備份的taw_rm_user表恢複到comtest下即可。

其中使用的關鍵SQL語句如下:

-- 備份測試庫中的taw_rm_user表create table comtest.taw_rm_user_bakasselect * from comtest.taw_rm_user-- 恢複正式庫中的taw_rm_user.password欄位declarerec_comtest comtest.taw_rm_user%rowtype;cursor cur_comtest isselect * from comtest.taw_rm_user;beginopen cur_comtest;loopfetch cur_comtest into rec_comtest;exit when cur_comtest%notfound;update com.taw_rm_userset com.taw_rm_user.password=rec_comtest.passwordwhere com.taw_rm_user.user_id=rec_comtest.user_id;end loop;close cur_comtest;commit;end;

這樣就可以實現在不更改其他所有資訊的情況下,將所有舊使用者的密碼恢複到從前。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.