Home » SQL & PL/SQL » SQL & PL/SQL » Creating a temp table and unique numbering
Creating a temp table and unique numbering [message #2612] Wed, 31 July 2002 02:58 Go to next message
Bryan Avery
Messages: 4
Registered: July 2002
Junior Member
I have a table which has two fields as the primary key, and these fields are alpha fields.
What I need to do is create a temp. table and create a unique number following the primary key.

The table currently looks like this:

CATEGORY SEWER
CATEGORY WATERPE
CATEGORY WATERPVC
DIVISION BELOWGR
DIVISION BUILDING
DIVISION LITRTURE
DIVISION UTILITY

and I would like to have a table looking like this:

11 CATEGORY SEWER
8 CATEGORY WATERPE
9 CATEGORY WATERPVC
4 DIVISION BELOWGR
1 DIVISION BUILDING
2 DIVISION LITRTURE
3 DIVISION UTILITY

Sounds quite simple, any ideas?
Re: Creating a temp table and unique numbering [message #2615 is a reply to message #2612] Wed, 31 July 2002 05:06 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
SQL> select * from temp order by cate,type;

CATE       TYPE
---------- ----------
CATEGORY   SEWER
CATEGORY   WATERPE
CATEGORY   WATERPVC
DIVISION   BELOWGR
DIVISION   BUILDING
DIVISION   LITRTURE
DIVISION   UTILITY
DIVISION   UTILITY

8 rows selected.

SQL> alter table temp add (id number);

Table altered.
SQL> ed
Wrote file afiedt.buf

  1  create table new_temp
  2  as
  3  select rownum id ,cate,type from
  4* (select cate,type from  temp order by cate,type)
SQL> /

Table created.

SQL> select * from new_temp;

        ID CATE       TYPE
---------- ---------- ----------
         1 CATEGORY   SEWER
         2 CATEGORY   WATERPE
         3 CATEGORY   WATERPVC
         4 DIVISION   BELOWGR
         5 DIVISION   BUILDING
         6 DIVISION   LITRTURE
         7 DIVISION   UTILITY
         8 DIVISION   UTILITY

8 rows selected.
----------------------------------------
check the data. 
Now you can drop the old temp table and rename new_temp to temp

Previous Topic: String search in large table
Next Topic: use value of one variable as a name of the second variable
Goto Forum:
  


Current Time: Tue Apr 23 07:37:22 CDT 2024