当前位置:网站首页>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 排查大 key 的4種方法,優化必備
- Postman关联
- [noip2008 improvement group] stupid monkey
- [mathematical modeling] differential equation -- sustainable development of fishing industry
- Selection of slow motion function
- [NOIP2008 提高组] 笨小猴
- MySQL if and ifnull use
- Some common skills on unity inspector are generally used for editor extension or others
- 优秀PM必须经历这3层蜕变!
- [try to hack] John hash cracking tool
猜你喜欢

Postman Association

yolov5 tensorrt加速

Lepton 无损压缩原理及性能分析

Postman断言

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
![[detailed steps of FreeRTOS shift value for the first time]](/img/73/a469eb2465bb2c5acaa4d018d3edd3.jpg)
[detailed steps of FreeRTOS shift value for the first time]

RT thread analysis - object container implementation and function
![[lgr-109] Luogu may race II & windy round 6](/img/fe/d5b67c7dff759c519a04da023630ea.png)
[lgr-109] Luogu may race II & windy round 6

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

DMA use of stm32
随机推荐
集合详解之 Map + 面试题
Distributed transaction solution
[lgr-109] Luogu may race II & windy round 6
Use sentinel to interface locally
Collection + interview questions
Flink kakfa data read and write to Hudi
驱动开发——第一个HelloDDK
The kernel determines whether peripherals are attached to the I2C address
Codeforces Round #804 (Div. 2)
Drive development - the first helloddk
Summary of three log knowledge points of MySQL
树莓派3.5寸屏幕白屏显示连接
DMA use of stm32
Crazy God said redis notes
Leetcode dynamic planning day 16
[数学建模] 微分方程--捕鱼业的持续发展
Principle and performance analysis of lepton lossless compression
JS quick start (II)
行业专网对比公网,优势在哪儿?能满足什么特定要求?
The video in win10 computer system does not display thumbnails