用表中的动态值更新列中的子字符串

时间:2018-07-13 08:38:07

标签: sql oracle

我在表中有1列,其值如下:

Activation period=0#Actual pay channel=214952491#Agreement id=1115151#Alternative charge code description=Fido Internet 75 - illimité
#Alternative packaging code description= #Alternative saving code description=Offre Fido Internet#Apply additional discount=N
#BCB ind=N#BCB seq no=0#Base charge amount=57.00000#Base offer ID=505613187#Base offer instance ID=5194671#Base offer item ID=505613107
#Bill frequency=1#Bulk billing code=Permanent#Business entity=0#Charge description=Fido Internet 75 - Unlimited#Charge identifier=D
#Charge nullify by discount ind=Y#Charge type=DSC#Check restriction ind=N#Commercial or residential=Residential#Commission id=006020
#Commitment end date=#Commitment period=#Commitment start date=#Component code=HS#Contract code=0#Contract desc code= #Contract dummy RC ind=N
#Contract revenue type=RC#CurrentCycleEndDate=00000000#CurrentCycleStartDate=00000000#Customer sub type=R#Customer type=F#Dealer code=CC
#Discount item ID=505613217#Discount type=NONE#Display charge ind= #Dummy ind=N#Dummy quotation ind=N#Dwelling code=07
#Equipment serial number= #Foreign manufacturer= #Foreign model= #Franchise=RCM#Included ind=N#LPIF indicator=N#Line of business=Internet
#Map area= #Multi dweling/single unit=MDU#Notification indicator=Y#Number of occurences=0#Occurrence in order=0#Offer connect Date=20180403
#Offer name=HS Fido Internet Embedded Discount 2018 - 3MF discount HS ACQ CON#Order id=10173580#Orig charge ind=N#Orig charge seq no=0
#Orig discount amount=0#Original charge amount=-57.00000#Original commitment start date=20201231#Override RC indicator=N#Override policy=N
#PRIT name=HS Fido Internet Embedded Discount 2018 - 3MF discount HS ACQ CON - RC Discount#Packaging code= #Packaging description= #Period scale=0
#Printing charge ind= #Product offer ID=505618817#Promotion effective date=20180403#Promotion expiration date=20180703#Promotion indicator=Y
#Quantity=1#RC expiration date=20180704#Rate=-57.00000#Rate area=RCM#Relation type= #Retrieve exemption=Y#SAM key=2330000367541#Sales channel= 
#Savings code=SC_CM_R_G9CSSSS#Savings description=Fido Internet Offer#Scale type=D#Service province=ON#Subscriber status=A#Subscriber sub type=Z
#Subscriber type=HS#Taxable amount=-57.00000#Waive ind= #

在这里,我需要用新值更新“促销有效期”值。我该如何使用更新命令。 请通过命令帮助我如何获得此结果?

谢谢

1 个答案:

答案 0 :(得分:0)

我更喜欢使用简单的字符串函数(例如INSTR,SUBSTR和REPLACE),但是在这种情况下,使用简单的REGEXP-REPLACE可读性更高:

with testtab as(
  select '[...]#Product offer ID=505618817#Promotion effective date=20180403#Promotion expiration date=20180703#Promotion indicator=Y
#[...]#Waive ind= #' as text from dual)
select regexp_replace(text, 'Promotion expiration date=\d*', 'Promotion expiration date=' || to_char(sysdate, 'YYYYMMDD') ) from testtab;

\ d *是0到无穷多个数字,例如''3453454356456345634563546。匹配直到#。这意味着它将替换Promotion expiration date=20180606Promotion expiration date=345665756567