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 :-

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 :-

In case there is more than one match :-

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

Appreciate the help. Thanks