declare
cursor cur_test is
select t.txt_desig,
m.segment_id,
s.code_type_direct,
case
when s.uom_dist_ver_lower = ‘FL‘ then
s.uom_dist_ver_lower || s.val_dist_ver_lower
else
to_char(s.val_dist_ver_lower)
end as val
from nvduser11.en_route_rte t
right join nvduser11.rte_seg s
left join fmap2.segment m
on s.segment_id = m.segment_id on
t.en_route_rte_id = s.en_route_rte_id;
begin
for c in cur_test loop
update fmap2.segment
set first =
(case
when first is null or first = ‘‘ then
c.txt_desig
else
to_char(first)
end),
second =
(case
when (first is not null or first != ‘‘) and
(second is null or second = ‘‘) then
c.txt_desig
else
to_char(second)
end),
third =
(case
when (second is not null or second != ‘‘) and
(first is not null or first != ‘‘) and (third is null or third = ‘‘) then
c.txt_desig
else
to_char(third)
end),
firstdirect =
(case
when first is null or first = ‘‘ then
c.code_type_direct
else
to_char(firstdirect)
end),
firstaltitude =
(case
when first is null or first = ‘‘ then
c.val
else
to_char(firstaltitude)
end),
seconddirect =
(case
when (first is not null or first != ‘‘) and
(second is null or second = ‘‘) then
c.code_type_direct
else
to_char(seconddirect)
end),
secondaltitude =
(case
when (first is not null or first != ‘‘) and
(second is null or second = ‘‘) then
c.val
else
to_char(secondaltitude)
end),
thirddirect =
(case
when (second is not null or second != ‘‘) and
(first is not null or first != ‘‘) and (third is null or third = ‘‘) then
c.code_type_direct
else
to_char(thirddirect)
end),
thirdaltitude =
(case
when (second is not null or second != ‘‘) and
(first is not null or first != ‘‘) and (third is null or third = ‘‘) then
c.val
else
to_char(thirdaltitude)
end)
where segment_id = c.segment_id;
end loop;
commit;
end;
oracle遍历表更新另一个表(一对多)
时间: 2024-11-03 03:46:04
oracle遍历表更新另一个表(一对多)的相关文章
如何使用MySQL一个表中的字段更新另一个表中字段
这篇文章主要介绍了如何使用MySQL一个表中的字段更新另一个表中字段,需要的朋友可以参考下 1,修改1列 ? 1 2 3 update student s, city c set s.city_name = c.name where s.city_code = c.code; 2,修改多个列 ? 1 2 3 update a, b set a.title=b.title, a.name=b.name where a.id=b.id ?子查询 ? 1 update student s set ci
SQL两表之间:根据一个表的字段更新另一个表的字段
1. 写法轻松,更新效率高: update table1 set field1=table2.field1, field2=table2.field2 from table2 where table1.id=table2.id 2. 常规方式,种写法相当于一个 Left join, 以外面的where为更新条数,如果不加where就是所有记录 update table1 set field1=(select top 1 field1 from table2 where table2.id=tab
mysql 两个关联表如何更新其中一个表的数据
今天遇到一个客户的数据更新问题,两个相关联的表,一个主表用于保存单据主要信息,一个副表用于保存单据的明细信息:现在要把主表的其中一个字段的数据更新到副表的一个字段中保存. 假设: A表是主表,有单号order_id.开单人operator.开单日期oper_date.备注memo等: B表是副表,有单号order_id.序号id.商品编码code.商品名称name.备注memo等. A表的备注是有数据的,B表的备注没有数据,现在要把A表的数据更新到B表,并且B表有数据的不能更新了.A表与B表是以
sql语句问题 通过联立两个表更新其中一个表的字段
============问题描述============ 有两个表a和b,a表中的字段有mobilehead(号码前7位),provincename,b表中有mobile(正常号码),provincename,需求是通过联立两个表,更新b表中provincename为空的数据. ============解决方案1============ 可以这样做 UPDATE b SET b.PN = a.PN FROM a WHERE b.PN = '
在SQLite中如何用一个表的字段更新另一个表
SQL语句: update table_1 set x = (select x from table_2 where table_1.y = table_2.y); 如果括号中临时建立的表中元素的个数小于table_1中元素个数或者只想更新table_1中部分x的值,可以在后面加where子句. Example:更新产品库存: update product set stock=(select stock from left where left.product_id=product.produc
sql 根据一个表更新 另一个表的例子及可能遇到的问题
例子: update a set a.name=b.name1 from a,b where a.id=b.id 例子延伸:更新的时候会把字符串 转为科学计数法 怎么办? 答:用 cast 转换一下 ,或者双cast update LoaneeExpand set LoaneeExpand.phone=cast(cast(tt.PHONE as decimal(18,0)) as nvarchar(50)) from LoaneeExpand ,tt where LoaneeExp
oracle插入或更新某一个指定列来执行触发器
表结构: create table TZ_GXSX ( ID VARCHAR2(15), PROJECT VARCHAR2(50), TXYX NUMBER(22) default '0', CDATE DATE, RISK VARCHAR2(10), DEGREE VARCHAR2(10), PROB VARCHAR2(10), PRESSURE_LEVEL VARCHAR2(20), NETWORKDIVISION VARCHAR2(20), AUTHOR VARCHAR2(20), INP
如何实现插入数据时自动更新另外一个表的内容
1事务:在程序中,将插入代码和更新代码包裹在一个事务里,失败后回滚,保证同时成功同时失败. 2存储过程:在数据库写存储过程,存储过程里面代码包裹在事务里,失败后回滚. 3触发器: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[tri_test] ON [dbo].[销售情况信息] AFTER INSERT AS BEGIN UPDATE dbo.库存基本信息 SET 商品现存数量 = 商品现存数量 -
Merge更新同步一个表
merge T2 --目标表using T1 --源表 on T1.id=T2.id --匹配条件 when matched then --匹配update set [name]=T1.[name]when not matched then --不匹配insert values(id,[name]); ------------------------------------------------------------------- PS:作库存对比的时候使用 原文地址