Home » SQL & PL/SQL » SQL & PL/SQL » Attention Todd Barry or Andrew
Attention Todd Barry or Andrew [message #40703] Fri, 01 November 2002 03:23 Go to next message
Viswa
Messages: 8
Registered: October 2002
Junior Member
Hi,

I have Tabel Named merge with the following Arributes and Data
merge
=====
src_id
mrg_id

Data
=====

src_id mrg_id
===============
101 102
102 103
103 104
104 105
235 200
3 4
4 5

here 101=102,102=103,103=104,104=105 Finally
101 = 105, That is for each src_id i have to find the lease child mrg_id.

I want to get the Outout like

src_id mrg_id
===============
101 102 105
102 103 105
103 104 105
104 105 105
235 200 200
3 4 5(since 3=4=5)
4 5 5

Please help me to proceed. Thanx in Advance

Viswa
Re: Attention Todd Barry or Andrew [message #40704 is a reply to message #40703] Fri, 01 November 2002 03:49 Go to previous message
Venkata Krishnayya Kommu
Messages: 13
Registered: July 2000
Junior Member
U write a function like nthis
create or replace function p1(src_id varchar(5)) return varchar2(5) as
s1 varchar2(5);
s2 varchar2(5);
p2 varchar(2);
begin
s1 := src_id;
begin
select P2 = 'F' from dual;
do while p2 = 'F'
begin
select s2 = mrg_id from ur_table
where src_id = s1;
s1 = s2
exception when no_data_found then
return s1;
end
return s1;
end
select src_id, mrg_id, p1(src_id) from ur_table;
Basically function will try to find the final src_id thru a loop. I didnt chek the function . Take it as a logic only.
I am currently working on sql server. So the syntax may be not correct. Chek it it should work
Regards
Krishna
select s1 = src_id from ur_table
where

select s2 =
Previous Topic: DATE CONVERSION
Next Topic: how to tokenise a varchar or string
Goto Forum:
  


Current Time: Sun Apr 28 20:51:39 CDT 2024