当前位置:网站首页>Oracle updates the data of different table structures and fields to another table, and then inserts it into the new table
Oracle updates the data of different table structures and fields to another table, and then inserts it into the new table
2022-04-23 21:25:00 【Plant a sweet smell】
Oracle Update and insert operations of different tables
In production , A table due to configuration problems A There is no data in one of the fields , Result in B The data in the table is completely null.
The current requirements are as follows : With the help of g_wo_sn C The data of serial_number, Then update the data to G_SN_IMEI_MANAGE A Tabular SN Column , The structure of the two tables is inconsistent , Then insert into C surface
namely : hold C Of serial_number Update to A Tabular SN
C The table structure is as follows
select a.*,rownum from g_wo_sn a where A.WORK_ORDER='WORK015903' and rownum<=9000;
B The table structure is as follows
select a.*,rownum from G_SN_IMEI_MANAGE a where a.WORK_ORDER='WORK015903' and rownum<=9000;
because C Table and A The table structure of the table is different , There is no same row data . But watch carefully A Table fields , We found that A Tabular NOT_BURN_IMEI This column has no data ,name You can use Oracle Built in functions for rownum Update data . Steps are as follows :
1. Update first A Tabular NOT_BURN_IMEI Field , Let it be arranged in numbers . namely NOT_BURN_IMEI=rownum. This is the most important step
update G_SN_IMEI_MANAGE set NOT_BURN_IMEI=rownum where WORK_ORDER='WORK015903';
2. After the C Tabular serial_number Update to A Tabular SN in
update G_SN_IMEI_MANAGE a set a.sn=(select t.serial_number from (select a.*,rownum as g from g_wo_sn a where A.WORK_ORDER='WORK015903' and rownum<=9000)t where t.g=a.NOT_BURN_IMEI) where a.work_order='WORK015903';
3. The last update A Tabular NOT_BURN_IMEI Field
update G_SN_IMEI_MANAGE set NOT_BURN_IMEI=null where WORK_ORDER='WORK015903';
4. Then insert into B In the table
insert into IMEI_SN_K1807 b (WORK_ORDER,PART_ID,SN,IMEI,UPDATE_USERID,UPDATE_TIME,FLAG)
(select WORK_ORDER,PART_ID,SN,IMEI,OPERATOR_ID,OPERATOR_TIME,FLG from G_SN_IMEI_MANAGE a where a.WORK_ORDER='WORK015903') ;
Of course , We can also use Excle File import . But when it comes to different data volumes of two tables , You can try rownum function , It's much easier to use than you think .
版权声明
本文为[Plant a sweet smell]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/110/202204200619557482.html
边栏推荐
- South Korea may ban apple and Google from offering commission to developers, the first in the world
- Unit function expansion
- Ubutnu20 installer centernet
- go defer
- C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
- 危机即机遇,远程办公效率为何会提升?
- Thinkphp5 + data large screen display effect
- 1. Finishing huazi Mianjing -- 1
- [leetcode refers to offer 25. Merge two sorted linked lists (simple)]
- Some grounded words
猜你喜欢
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
2.整理华子面经--2
Plato Farm元宇宙IEO上线四大,链上交易颇高
What if Jenkins forgot his password
Problem brushing plan -- dynamic programming (III)
Xiaomi mobile phone has abandoned the "Mi" brand all over the world and switched to the full name brand of "Xiaomi"
Resolve the "chromedriver executable needs to be in path" error
Deep understanding of modern mobile GPU (continuously updating)
[※ leetcode refers to offer 46. Translate numbers into strings (medium)]
Mysql database common sense storage engine
随机推荐
How to make Jenkins job run automatically after startup
Graph traversal - BFS, DFS
ubutnu20安装CenterNet
How to use the project that created SVN for the first time
Norm normalization in tensorflow and pytorch of records
Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
presto on spark 支持3.1.3记录
Resolve the "chromedriver executable needs to be in path" error
Detectron2 using custom datasets
airbase 初步分析
mmap、munmap
Introduce structured concurrency and release swift 5.5!
Explore ASP Net core read request The correct way of body
Mysql database common sense storage engine
Plato Farm元宇宙IEO上线四大,链上交易颇高
DeNO 1.13.2 release
JS to get the browser and screen height
Deno 1.13.2 发布
[leetcode refers to offer 22. The penultimate node in the linked list (simple)]