Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Unique(ish) sequence question, bulk collect

Re: Unique(ish) sequence question, bulk collect

From: sundeep maini <sundeep_maini_at_yahoo.com>
Date: Fri, 20 Feb 2004 13:17:26 -0800 (PST)
Message-ID: <20040220211726.6443.qmail@web11807.mail.yahoo.com>


You can use the analytical function to build a single SQL for update and they blaze. Here is my example:

DROP TABLE temp;
DROP SEQUENCE temp_seq;
CREATE SEQUENCE temp_seq CACHE 10;
CREATE TABLE temp (id INTEGER, distinct_row_id integer, x varchar2(10), y varchar2(10), z varchar2(10),  CONSTRAINT temp_pk PRIMARY KEY(id));

insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'1','1','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'1','1','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'2','1','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'3','1','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'3','1','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'1','2','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'1','2','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'1','2','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'4','1','1');
insert into temp(id,x,y,z) values (temp_seq.NEXTVAL,'4','1','1');
COMMIT;
SELECT *
  FROM temp;
ID	DISTINCT_ROW_ID	X	Y	Z
1		1	1	1
2		1	1	1
3		2	1	1
4		3	1	1
5		3	1	1
6		1	2	1
7		1	2	1
8		1	2	1
9		4	1	1
10		4	1	1

UPDATE temp

   SET distinct_row_id = (

       SELECT row_num
	     FROM (  
              SELECT x,y,z, row_number() OVER(order by x,y,z) 
row_num
                FROM temp
               GROUP BY x,y,z
	          ) temp_in
		WHERE temp.x = temp_in.x
		  AND temp.y = temp_in.y
		  AND temp.z = temp_in.z
	  );  

COMMIT;
SELECT *
  FROM temp;
ID	DISTINCT_ROW_ID	X	Y	Z
1	1	1	1	1
2	1	1	1	1
3	3	2	1	1
4	4	3	1	1
5	4	3	1	1
6	2	1	2	1
7	2	1	2	1
8	2	1	2	1
9	5	4	1	1
10	5	4	1	1


Sundeep Maini
Consultant
Currently on Assignement at Caterpillar Peoria sundeep_maini_k_at_cat.com



Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools

Please see the official ORACLE-L FAQ: http://www.orafaq.com

To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------
Received on Fri Feb 20 2004 - 16:53:10 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US