从列中提取数据并在Oracle中的同一个表中更新另一个coulmn [英] Extract Data from a column and Update another coulmn in same table in Oracle

查看:80
本文介绍了从列中提取数据并在Oracle中的同一个表中更新另一个coulmn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Oracle'tEvents'中有一个表,包含'Action'列,其中包含两个EventID的字符串,如您在示例中所示。我的要求是,我需要Extrcat两个EventID并分别更新colummn EventID1和EventID2。表包含数百万条记录。

 KEY | USERID |行动| EventID1 | EventID2 |日期

309629 | U099439 |更新了事件249的相关事件9400的行动项目NULL | NULL | 11-AUG-99

解决方案

您可以使用以下查询





 选择  CASE   INSTR(testres,'  |')> 0 那么 SUBSTR(testres, 1 ,INSTR(testres,'  |') -  1) ELSE  testres  END  EventID1,
CASE 何时 INSTR(testres, ' |')> 0 那么 SUBSTR(testres,INSTR(testres,' |')+ 1,LENGTH(testres)) ELSE NULL END as EventId2 ,
testres,测试来自
选择
CASE INSTR(test,' New Action')> 0 THEN REPLACE(REPLACE(test,' 事件'的新操作项,' ' ),' 已添加' ' '
INSTR(test,' 更新后的操作')> 0 那么 REPLACE(REPLACE (test,' 更新了事件'的操作项,' '),' for Associated Event' ' |'
INSTR(test,' 被删除')> 0 那么 REPLACE(REPLACE(测试,' 事件的行动项目' '),' < span class =code-string>已删除',' '
END testres,

test 来自
SELEC t ' 更新了事件249的行动项目,关联事件9400' test union
select 事件249的新操作项已添加 来自 dual union
选择 ' 事件249的操作项被删除' 来自
)A)B


I have a table in Oracle 'tEvents', Containing column 'Action' which having string containg Two EventIDs as you can see in example. My requirement, is I need to Extrcat the Both EventIDs and update the colummn EventID1 and EventID2 respectively.The Table contains millions of record.

KEY | USERID | Action | EventID1 | EventID2 | Date

309629 | U099439 | Updated Action Item for Event 249 for Associated Event 9400 | NULL | NULL | 11-AUG-99

解决方案

You can use the below query


Select CASE When INSTR (testres,'|')>0 THEN SUBSTR (testres,1,INSTR (testres,'|')-1) ELSE testres END EventID1,
CASE When INSTR (testres,'|')>0 THEN SUBSTR (testres,INSTR (testres,'|')+1,LENGTH(testres))ELSE NULL END as EventId2,
testres,test from (
select
CASE When INSTR (test,'New Action')>0 THEN REPLACE(REPLACE(test,'New Action Item for Event ',''),' has been Added','')
     When INSTR (test,'Updated Action')>0 THEN REPLACE(REPLACE(test,'Updated Action Item for Event ',''),' for Associated Event ','|')
     When INSTR (test,' is deleted')>0 THEN REPLACE(REPLACE(test,'Action Item for Event ',''),' is deleted','')
END testres,

test from(
select 'Updated Action Item for Event 249 for Associated Event 9400' test from dual union
select 'New Action Item for Event 249 has been Added' from dual union
select 'Action Item for Event 249 is deleted' from dual
)A )B


这篇关于从列中提取数据并在Oracle中的同一个表中更新另一个coulmn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆