当前位置:网站首页>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;
边栏推荐
- [NOIP2008 提高组] 笨小猴
- Crazy God said redis notes
- DMA use of stm32
- Postman测试报告
- [noip2009 popularization group] score line delimitation
- Distributed transaction solution
- Postman Association
- [05-1, 05-02, 05-03] network protocol
- GAMES202-WebGL中shader的编译和连接(了解向)
- Postman pre script - global variables and environment variables
猜你喜欢

Principle and performance analysis of lepton lossless compression

Flody的应用

二叉树基本知识和例题

几种RS485隔离通讯的方案介绍

Visio draw fan

JS quick start (II)

Delete subsequence < daily question >

Class inheritance in yyds dry inventory C
![[mathematical modeling] differential equation -- sustainable development of fishing industry](/img/7c/2ab6f2a34bc2c97318537ec8e0b0c5.png)
[mathematical modeling] differential equation -- sustainable development of fishing industry

Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
随机推荐
[NOIP2009 普及组] 分数线划定
最高法院,离婚案件判决标准
Principle and performance analysis of lepton lossless compression
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
Leetcode dynamic planning day 16
Delete subsequence < daily question >
RTP GB28181 文件测试工具
Selection sort
C'est un petit résumé de l'étude.
idea一键导包
Quelques conseils communs sur l'inspecteur de l'unit é, généralement pour les extensions d'éditeur ou d'autres
EditorUtility. The role and application of setdirty in untiy
团队协作出了问题,项目经理怎么办?
Weng Kai C language third week 3.1 punch in
Platformio create libopencm3 + FreeRTOS project
A blog to achieve embedded entry
Some common skills on unity inspector are generally used for editor extension or others
Rce code and Command Execution Vulnerability
[mathematical modeling] differential equation -- sustainable development of fishing industry
Postman断言