Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Finding a common letter between two strings

User_FRTCMSep 23 2015 — edited Sep 23 2015

Hi,

I need help to find a common string between consequent strings from a table. Below is a sample scenario that you can refer to replicate and suggest.

create table test_marine

(

p_id varchar2(50),

t_id varchar2(50),

h_code varchar2(40),

misc_type number

);

insert into test_m values('1','100','ABC',1);

insert into test_m values('1','101','ABCD',1);

insert into test_m values('1','102','BC',1);

insert into test_m values('1','103','B',1);

COMMIT;

Data will look like below :-

OTN.JPG

What I need to do here is - I want to pick the all the h_code column values on the whole at once where p_id = 1 , and scan through all the H_CODE values one by one. Any other viable approach also that can help will be good.

Example - I pick ABC for 100, I check if A is common across 101,102,103, if yes, log it somewhere. Next check if B exists in the whole.

My Final Output should be like this :-

OTN2.JPG

In case there is more than one match :-

OTN4.JPG

In case there is no match, the value can come as anything like below :-

otn3.JPG

Appreciate the help. Thanks

This post has been answered by BluShadow on Sep 23 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 21 2015
Added on Sep 23 2015
9 comments
1,524 views