Home » SQL & PL/SQL » SQL & PL/SQL » Problem in Insersion (SQL, 11g Release 11.2.0.2.0 ,Win7)
Problem in Insersion [message #623195] Fri, 05 September 2014 12:25 Go to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
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

Re: Problem in Insersion [message #623199 is a reply to message #623195] Fri, 05 September 2014 13:29 Go to previous messageGo to next message
LKBrwn_DBA
Messages: 487
Registered: July 2003
Location: WPB, FL
Senior Member
Nice homework, what you got done?

[Updated on: Fri, 05 September 2014 14:52] by Moderator

Report message to a moderator

Re: Problem in Insersion [message #623200 is a reply to message #623199] Fri, 05 September 2014 14:00 Go to previous message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
I'm an ETL developer and its a real scenario...Might be this thing not handle by SQL, we need to incorporate PLSQL, mainly collection but not sure now.
Previous Topic: How to escape '
Next Topic: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
Goto Forum:
  


Current Time: Tue Apr 23 08:58:51 CDT 2024