当前位置:网站首页>Three methods of Oracle two table Association update
Three methods of Oracle two table Association update
2022-07-06 04:58:00 【Terence-Wang】
Not much said , Let's do the experiment .
preparation
Create the following table data
drop table demo_t1;
drop table demo_t2;
CREATE TABLE DEMO_T1
(
FNAME VARCHAR2(20)
, FMONEY VARCHAR2(20)
);
ALTER TABLE demo_t1 ADD PRIMARY KEY(FNAME);
insert into demo_t1 (fname,fmoney) values('A','20');
insert into demo_t1 (fname,fmoney) values('B','30');
CREATE TABLE DEMO_T2
(
FNAME VARCHAR2(20)
, FMONEY VARCHAR2(20)
);
ALTER TABLE demo_t2 ADD PRIMARY KEY(FNAME);
insert into demo_t2 (fname,fmoney) values('C','10');
insert into demo_t2 (fname,fmoney) values('D','20');
insert into demo_t2 (fname,fmoney) values('A','100');
Current demand : reference T2 surface , modify T1 surface , The modification condition is two tables fname Columns are consistent .
The way 1:update
UPDATE DEMO_T1 t1
SET T1.FMONEY = (select T2.FMONEY from DEMO_T2 T2 where T2.FNAME = T1.FNAME)
WHERE EXISTS(SELECT 1 FROM DEMO_T2 T2 WHERE T2.FNAME = T1.FNAME);
If you update multiple fields at the same time, you can refer to the following syntax :
UPDATE DEMO_T1 t1
SET ( Field one , Field 2 ,...) = (select Field one , Field 2 ,... from DEMO_T2 T2 where T2.FNAME = T1.FNAME)
WHERE EXISTS(SELECT 1 FROM DEMO_T2 T2 WHERE T2.FNAME = T1.FNAME);
The way 2: Inline view update
Be careful : Tables requiring data retrieval , This field must be a primary key or have a unique constraint
UPDATE (
select t1.fmoney fmoney1,t2.fmoney fmoney2 from demo_t1 t1,demo_t2 t2 where t1.fname = t2.fname
)t
set fmoney1 =fmoney2;
The way 3:merge to update
merge into demo_t1 t1
using (select t2.fname,t2.fmoney from demo_t2 t2) t
on (t.fname = t1.fname)
when matched then
update set t1.fmoney = t.fmoney;
边栏推荐
- Redis has four methods for checking big keys, which are necessary for optimization
- win10电脑系统里的视频不显示缩略图
- Nestjs配置文件上传, 配置中间件以及管道的使用
- 也算是學習中的小總結
- [NOIP2009 普及组] 分数线划定
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Visio draws Tai Chi
- Platformio create libopencm3 + FreeRTOS project
- Pagoda configuration mongodb
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
猜你喜欢
几种RS485隔离通讯的方案介绍
[classic example] binary tree recursive structure classic topic collection @ binary tree
Fuzzy -- basic application method of AFL
RTP GB28181 文件测试工具
Pagoda configuration mongodb
Use sentinel to interface locally
Programmers' position in the Internet industry | daily anecdotes
Postman pre script - global variables and environment variables
Visio draw fan
Introduction of several RS485 isolated communication schemes
随机推荐
win10电脑系统里的视频不显示缩略图
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
The underlying structure of five data types in redis
团队协作出了问题,项目经理怎么办?
关于es8316的音频爆破音的解决
Summary of redis AOF and RDB knowledge points
项目经理,你会画原型嘛?项目经理需要做产品设计了?
2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
[05-1, 05-02, 05-03] network protocol
比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
Codeforces Round #804 (Div. 2)
Sqlserver query results are not displayed in tabular form. How to modify them
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
Delete subsequence < daily question >
It is also a small summary in learning
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
Use sentinel to interface locally
Platformio create libopencm3 + FreeRTOS project
驱动开发——第一个HelloDDK