Hi All
Appreciate if someone help me out. I have the following data:
Drop table
Drop table parent_mst;
drop table parent_dtl;
drop table p1;
drop table p2;
drop SEQUENCE p_seq;
delete from parent_mst;
delete from parent_dtl;
delete from p1;
delete from p2;
Create table and Sequence
CREATE SEQUENCE p_seq
START WITH 1
INCREMENT BY 1;
create table p1
(
grp number(3),
nel number(4)
);
---------
create table p2
(
grp number(3),
per number(4)
);
create table parent_mst
(
grp number(3),
nel number(4),
ppk_seq number(5)
);
create table parent_dtl
(
grp number(3),
per number(4),
ppk_seq number(5)
);
Insertion
INSERT INTO p1
SELECT 100 grp,
8000 nel
FROM dual
UNION ALL
SELECT 200 grp,
1000 nel
FROM dual
UNION ALL
SELECT 300 grp,
1000 nel
FROM dual;
INSERT INTO p2
SELECT 100,
200
FROM dual
UNION ALL
SELECT 100,
300
FROM dual
UNION ALL
SELECT 100,
500
FROM dual
UNION ALL
SELECT 200,
400
FROM dual
UNION ALL
SELECT 200,
600
FROM dual
UNION ALL
SELECT 500,
600
FROM dual;
insert into parent_mst
(select 100,320,10 from dual);
--------------------
My requirement is that I need to insert records in parent_mst and parent_dtl by using data of p1 and p2 tables.
the way of populating data in tables are:
Rules
--System get all unique PER against GRP from p2 table for example for grp=100 we have PER like 200,300,500
-- Go to p1 table and match grp and if exist then create 1 record in parent_mst table against grp and NEL (unique combination) and get its column ppk_seq and insert that ppk_seq with set of data.
Required Result
Data should be inserted in parent_mst table
GRP NEL ppk_seq
100 8000 1
100 9000 2
200 1000 3
Data should be inserted in parent_dtl table
GRP PER ppk_seq
100 200 1
100 300 1
100 500 1
100 200 2
100 300 2
100 500 2
200 400 3
200 600 3
Please let me know if you have any question, Sorry about my poor English. Thanks
Note:-This is an additional logic that I posted before www.orafaq.com/forum/m/623192/#msg_623192
[Updated on: Fri, 05 September 2014 12:28]
Report message to a moderator