create table table1(
field1 varchar2(255),
field2 varchar2(255)
)
Table created.
insert into table1(field1, field2) values('this is 1983', 'THE YEAR')
1 row(s) inserted.
insert into table1(field1, field2) values('this is 1983', null)
1 row(s) inserted.
select * from table1
FIELD1 | FIELD2 | this is 1983 | - | this is 1983 | THE YEAR |
---|
select regexp_replace(
field1, -- field to break apart
'^(.*) (\d{4})$', -- regular expression building groups
'\1 '||field2|| ' \2') -- specify how the groups should join together
from table1
REGEXP_REPLACE(FIELD1,'^(.*)(\D{4})$','\1'||FIELD2||'\2') | this is 1983 | this is THE YEAR 1983 |
---|
select
case
when field2 is not null then regexp_replace(field1,'^(.*) (\d{4})$', '\1 '||field2|| ' \2')
else field1
end test_result
from table1
TEST_RESULT | this is 1983 | this is THE YEAR 1983 |
---|
update table1
set field1 = case
when field2 is not null then regexp_replace(field1,'^(.*) (\d{4})$', '\1 '||field2|| ' \2')
else field1
end
2 row(s) updated.
select * from table1
FIELD1 | FIELD2 | this is 1983 | - | this is THE YEAR 1983 | THE YEAR |
---|