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!

[8i] Is it possible to add a row number that increases based on a column?

696240Feb 18 2010 — edited Feb 18 2010
I have the following sample table and data:
CREATE TABLE ords
(	ord_nbr		NUMBER	NOT NULL
,	step_nbr	NUMBER
,	area_code	VARCHAR2(2)
	CONSTRAINT caln_pk PRIMARY KEY (ord_nbr)
);

INSERT INTO	ords
VALUES (1,1,'A1');
INSERT INTO	ords
VALUES (1,2,'B1');
INSERT INTO	ords
VALUES (1,3,'B1');
INSERT INTO	ords
VALUES (1,4,'B2');
INSERT INTO	ords
VALUES (1,5,'A1');
INSERT INTO	ords
VALUES (1,6,'C1');
INSERT INTO	ords
VALUES (1,7,'X1');
INSERT INTO	ords
VALUES (1,8,'C2');
INSERT INTO	ords
VALUES (1,9,'C2');
INSERT INTO	ords
VALUES (1,10,'Z9');
The results I want to get look like:
ORD_NBR	STEP_NBR	AREA_CODE	SEQ_NBR
-----------------------------------------------
1	1		A1		1
1	2		B1		2
1	3		B1		2
1	4		B2		3
1	5		A1		4
1	6		C1		5
1	7		X1		6
1	8		C2		7
1	9		C2		7
1	10		Z9		8
I only want the SEQ_NBR to increase if the area changes... I'm wondering if there's I need to turn this into a hierarchical query somehow, so that there's some relationship between step 1 and step 2, step 2 and step 3, etc.

I've played around with ROW_NUMBER, RANK, and DENSE_RANK, but I can't seem to figure out how to add that SEQ_NBR column...

Any suggestions?
This post has been answered by Frank Kulash on Feb 18 2010
Jump to Answer

Comments

663012
I changed the java wrappers using sqlj to a webservice. This scenario is working and returning the varray within the backing bean. The only real fix I had to make was to the connection.xml file for the correct port setting.
663012
Package.procedure with input as number and output as varray using webservice.
1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 18 2010
Added on Feb 18 2010
4 comments
2,079 views