Skip to Main Content
  • Questions
  • maping columms and replace with another strings

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, venkatesh.

Asked: July 20, 2016 - 7:08 am UTC

Last updated: July 20, 2016 - 9:52 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom,

Any one would you assist me regarding my issue..

step1:
I have two tables and data like below.

table 1:
create table component(id number , comptest varchar2(20) , apptext varchar2(20);
insert into component values(1,'[pula]','venkatesh');
insert into component values(2,'[poola]','mahesh');
insert into component values(3,'[annapareddy]','teja');

id comptest apptext
--- ----- --------
1 [pula] venkatesh
2 [poola] mahesh
3 [annapareddy] teja

tabble2:
create table presentation(pid number , pname vchar2(20));
insert into presentation values(1,'anusri[pula]');
insert into presenatation values(2,'srinivas[poola]');
insert into presentation values(3,'giri[annapareddy]');


pid pname
--- -----
1 anusri[pula]
2 srinivas[poola]
3 giri[annapareddy]


step 2:

I need to map the comptext and pname .

comparison like this

a.I need map comptest [pula] with pname [pula] if both [pula] match then i need to replace comptest [pula] with apptext venkatest in pname [pula].
b.I need map comptest [poola] with pname [poola] if both [poola] match then i need to replace comptest [poola] with apptext mahesh in pname [poola].
c.I need map comptest [annapareddy] with pname [annapareddy] if both [annapareddy] match then i need to replace comptest [annapareddy] with apptext
teja in pname [annapareddy].


my final result would be like this:

presentation:
pname
------
anusrivenkatesh
srinivasmahesh
giriteja





For this i need pl-sql script .
I given sample tables and samples data.
my actual tables contains thousands of rows .I need the updated pname in each row in presenatation table.




and Chris said...

You want to change the values in the presentation table?

In that case, you just need to turn the select from your previous question into an update:

create table component(id number , comptest varchar2(20) , apptext varchar2(20));

insert into component values(1,'[pula]','venkatesh');
insert into component values(2,'[poola]','mahesh');
insert into component values(3,'[annapareddy]','teja');

create table presentation(pid number , pname varchar2(20));

insert into presentation values(1,'anusri[pula]');
insert into presentation values(2,'srinivas[poola]');
insert into presentation values(3,'giri[annapareddy]');

commit;

update presentation
set    pname = (
  select replace(pname, comptest, apptext) from component 
  where  instr(pname, comptest) > 0
);

select * from presentation;

PID  PNAME            
1    anusrivenkatesh  
2    srinivasmahesh   
3    giriteja


https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9530587800346454386

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

venkatesh p, July 26, 2016 - 9:42 am UTC

I appreciate for your quick response to my Issue.