Home » SQL & PL/SQL » SQL & PL/SQL » Insert a Column
Insert a Column [message #22011] Tue, 17 September 2002 02:41 Go to next message
Ishan Parinda
Messages: 1
Registered: September 2002
Junior Member
I have a table wich has 4 columns.I want to insert a new column as the 3rd column, not as the last column.

Can you tell me how to do this

ThankX
Reg's
Parinda
Re: Insert a Column [message #22013 is a reply to message #22011] Tue, 17 September 2002 05:06 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
SQL> desc dept
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ------------------------------------
 DEPTNO                                                         NUMBER(2)
 DNAME                                                          VARCHAR2(14)
 LOC                                                            VARCHAR2(13)

SQL> alter table dept add(new_Col number);

Table altered.

SQL> desc dept
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ------------------------------------
 DEPTNO                                                         NUMBER(2)
 DNAME                                                          VARCHAR2(14)
 LOC                                                            VARCHAR2(13)
 NEW_COL                                                        NUMBER

SQL> ed
Wrote file afiedt.buf

  1  create table new_dept
  2  as
  3* (select deptno,dname,new_Col,loc from dept)
SQL> /

Table created.

SQL> select * from new_dept;

    DEPTNO DNAME             NEW_COL LOC
---------- -------------- ---------- -------------
        10 ACCOUNTING                NEW YORK
        20 RESEARCH                  DALLAS
        30 SALES                     CHICAGO
        40 OPERATIONS                BOSTON

now drop the old dept and rename new_dept to dept
Re: Insert a Column [message #22017 is a reply to message #22011] Tue, 17 September 2002 08:18 Go to previous message
jiltin
Messages: 44
Registered: September 2002
Member
wherever you add a column using alter table add column, it is going to add at the last column.
If you want that to be specific, you can do it only while creating it. Hence, you need to drop
and recreate the table, be careful not to loose the data. You may need to create a temp table
with data and then drop and recreate the table and reload the data from temp table

jiltin
Previous Topic: Re: Tablespace name retrieval
Next Topic: Re: Reverse Pivot - Debug Me?
Goto Forum:
  


Current Time: Sun May 05 21:15:46 CDT 2024