/*
The requirement for this data;
4 'pk'
5, null
6, null
9, 'jk'
13, 'jk'
14, null
is that a Group identifier be associated with each id,
where the id's form a series.
For example, rows 4, 5 and 6 would form Group 1
whereas 9 would form a group on its own, since
no id precedes it or follows it in a series.
Finally, 13 and 14 would form the final group.
The technique is known as Tabibitosan and has
been well documented by Aketi Jyuuzou in the following thread
https://forums.oracle.com/forums/thread.jspa?threadID=1005478&start=0&tstart=0
*/
-- This is merely an example of the technique;
with t as
(
select 4 id, 'pk' lk from dual union all
select 5, null from dual union all
select 6, null from dual union all
select 9, 'jk' from dual union all
select 13, 'jk' from dual union all
select 14, null from dual
)
select id, lk, 'LKG'|| dense_rank() over (order by sgroup) lkg_grp
from
(
select id
,lk
,id - row_number () over (order by id) sgroup
from t)
order by id;
ID LK LKG_GRP
--- -- -------
4 pk LKG1
5 LKG1
6 LKG1
9 jk LKG2
13 jk LKG3
14 LKG3
I use this blog as a dumping ground for various scripts as well as solutions to Maths problems.
Labels
- Alter (2)
- Analytic functions (2)
- AQ (2)
- AWR (4)
- Collections (2)
- Connect By (2)
- Constraints (7)
- Date/Time calculations (3)
- Dynamic SQL (4)
- Explain Plan (1)
- Formatting (3)
- Functions (1)
- Generating Functions (1)
- Indexes (7)
- Insert (3)
- JMS (3)
- Joins (4)
- LOB (3)
- locking (5)
- Partitions (3)
- Performance (10)
- Security (1)
- SQL Plus (3)
- Tabibitosan (1)
- Triggers (1)
- Views (1)
- XML (4)
Script categories
- Performance (10)
- Constraints (7)
- Indexes (7)
- locking (5)
- AWR (4)
- Dynamic SQL (4)
- Joins (4)
- XML (4)
- Date/Time calculations (3)
- Formatting (3)
- Insert (3)
- JMS (3)
- LOB (3)
- Partitions (3)
- SQL Plus (3)
- AQ (2)
- Analytic functions (2)
- Collections (2)
- Connect By (2)
- Explain Plan (1)
- Functions (1)
- Security (1)
- Triggers (1)
- Views (1)
No comments:
Post a Comment