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!

Splitting rows based on count

user9229402Sep 24 2014 — edited Sep 25 2014

i am trying to write a query based on below inputs.

emp table

empid

1

2

3

4

5

6

7..

..

23

Actual requirement, need to generate files based on row counts. so i am preparing the query. which gives header and detail records. Post to that unix script will run this query and place the result into one file. Then based on the header record, file will be split-ted into multi files. So each file will have one header and its detail records.

output:-

select header records

union

select detail records

sample header records:

emp_current date_Nth set, No.of Records,Nth set, N of sets.

emp_20140924_001,5,1,5      -- 1-5 records

emp_20140924_002,5,2,5      -- 6-10 records

emp_20140924_003,5,3,5      -- 11-15 records

emp_20140924_004,5,4,5      -- 16-20 records

emp_20140924_005,3,5,5      -- 21-23 records

sample detail records

emp_current date_Nth set, empid(Nth set is in header records)

emp_20140924_001, 1

emp_20140924_001, 2

emp_20140924_001, 3

emp_20140924_001, 4

emp_20140924_001, 5

emp_20140924_002, 6

emp_20140924_002, 7

emp_20140924_002, 8

emp_20140924_002, 9

emp_20140924_002, 10

emp_20140924_003, 11

emp_20140924_003, 12

... and so on...

emp_20140924_005, 22

emp_20140924_005, 23..

Please provide suggestions to achieve this. Thanks in advance.

Message was edited by: user9229402 - Added more details

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2014
Added on Sep 24 2014
6 comments
1,416 views