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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Need to generate count by using sequence

Shadow123Dec 15 2016 — edited Dec 15 2016

Oracle 11g

Hi Gurus

I appreciate if someone help me out. I have the following sample data:

Sample data

CREATE SEQUENCE  file_SEQ  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 100 CACHE 20 NOORDER  NOCYCLE ;
/
create table test4
(
file_number number,
seq_no number
);
/
insert into test4
select 10,null from dual union all
select 10,null from dual union all
select 10,null from dual union all
select 20,null from dual union all
select 20,null from dual union all
select 30,null from dual
;
/
select file_number,dense_rank() over (order by file_number)  dnk 
from test4

/

Query Output

FILE_NUMBER, DNK

10                          1

10                          1

10                          1

20                          2

20                          2

30                          3

Required Output

FILE_NUMBER, DNK

10                          100

10                          100

10                          100

20                          101

20                          101

30                          103

Rules:

If you noticed that I created sequence name as file_SEQ, system should  user this sequence to generate dnk column  and if file_number change then get next sequence.

So far I created the below query but it is not working.

Query

select file_number,dense_rank() over (order by file_number) + file_SEQ.nextval  dnk 

from test4

Query Output

10 101

10 102

10 103

20 105

20 106

30 108

but due to nextval , it is creating counting without grouping of file_number.

This post has been answered by Saubhik on Dec 15 2016
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 12 2017
Added on Dec 15 2016
4 comments
3,423 views