I have an input dataset that looks like this:
header1,null,null,null
null,1,X,Y,Z
null,2,X,Y,Z
null,3,X,Y,Z
header2,null,null,null
null,4,X,Y,Z
null,5,X,Y,Z
null,6,X,Y,Z
I'd like to write a query against that input to return a result set that looks like this:
header1,1,X,Y,Z
header1,2,X,Y,Z
header1,3,X,Y,Z
header2,4,X,Y,Z
header2,5,X,Y,Z
header2,6,X,Y,Z
I'm on Oracle 11g R2. I've been looking at the Oracle analytics intro found here: http://www.oracle-base.com/articles/misc/analytic-functions.php
I'm thinking there is a solution but I've not found it. The problem I think is that I have nothing to really group by. My only 'indicator' is to repeat the header value until I hit a set of nulls, then grab the next header and repeat it until I hit some nulls. So order is important, but you can see we have no column to order by.
Below are a couple quick scripts to build the test table and insert the rows.
Thanks you.
create table test (
col01 varchar2(10),
col02 varchar2(10),
col03 varchar2(10),
col04 varchar2(10))
insert into test values ('header1',null,null,null);
insert into test values (1,'X','Y','Z');
insert into test values (2,'X','Y','Z');
insert into test values (3,'X','Y','Z');
insert into test values ('header2',null,null,null);
insert into test values (4,'X','Y','Z');
insert into test values (5,'X','Y','Z');
insert into test values (6,'X','Y','Z');