当前位置:网站首页>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
边栏推荐
- Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
- Pytorch selects the first k maximum (minimum) values and their indexes in the data
- mmap、munmap
- Unit function expansion
- [leetcode refers to offer 52. The first common node of two linked lists (simple)]
- Assertionerror: invalid device ID and runtimeerror: CUDA error: invalid device ordinal
- Is rust more suitable for less experienced programmers?
- Prim、Kruskal
- How to make Jenkins job run automatically after startup
- Graph traversal - BFS, DFS
猜你喜欢
[※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]
[leetcode refers to offer 22. The penultimate node in the linked list (simple)]
Recommended usage scenarios and production tools for common 60 types of charts
1. Finishing huazi Mianjing -- 1
DeNO 1.13.2 release
Is rust more suitable for less experienced programmers?
Two Stage Detection
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
[leetcode refers to offer 25. Merge two sorted linked lists (simple)]
随机推荐
ROS learning notes - tutorial on the use of ROS
mmap、munmap
matplotlib. Pyplot partition drawing
ros功能包内自定义消息引用失败
pytorch 1.7. The model saved by X training cannot be loaded in version 1.4 or earlier
Keywords static, extern + global and local variables
[※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]
DW basic course (II)
1. Finishing huazi Mianjing -- 1
Alibaba cloud responded to the disclosure of user registration information
Some thoughts on super in pytorch, combined with code
Addition, deletion, modification and query of MySQL advanced table
YOLOv5 Unable to find a valid cuDNN algorithm to run convolution
Lunch on the 23rd day at home
Reference of custom message in ROS function pack failed
go defer
Deep analysis of C language function
Write table of MySQL Foundation (create table)
Mysql database common sense storage engine
Problem brushing plan -- dynamic programming (III)