How to rename a column name in a table? Thanks first!

I tried to drop a column age from table student by writing the
following in the sql plus environment as :
SQL> alter table student drop column age ;
but I found the following error
ORA-00905: 缺少关键字 (Lack of Key word)
I have oracle enterprise edition 8.0.5 installed at windows 2000
thank you
And I want to know how to rename a column name in a table?
thanks

In Oracle 8i, your syntax would have worked.  However, if I
recall correctly, in Oracle 8.0, you can't rename or drop a
column directly.  One way to get around that problem is to
create another table based on a select statement from your
original table, providing the new column name as an alias if you
want to change the column name, or omitting that column from the
select statement if you just want to drop it.  Then drop the
original table.  Then re-create the original table based on a
select statement from the other table.  Then you can drop the
other table.  Here is an example:
CREATE TABLE temporary_table_name
AS
SELECT age AS new_column_name,
       other_columns
FROM   student
DROP TABLE student
CREATE TABLE student
AS
SELECT *
FROM   temporary_table_name
DROP TABLE temporary_table_name
Something that you need to consider before doing this is
dependencies.  You need to make a list of all your dependecies
before you do this, so that you can re-create them afterwards. 
If there are a lot of them, it might be worthwhile to do
something else, like creating a view with an alias for the
column or just providing an alias in a select.  It depends on
what you need the different column name for.

Similar Messages

  • How to rename the column name in oracle 8i?

    hi,
    Does anyone know how to rename the column name in oracle 8i?My method was drop the relationship key first then delete the old column,finally add the new column.
    Thanks for your replay.
    jing

    There is no facilty to rename a column name in Oracle 8i. This is possible from Oracle 9.2 version onwards.
    For you task one example given below.
    Example:-
    Already existed table is ITEMS
    columns in ITEMS are ITID, ITEMNAME.
    But instead of ITID I want ITEMID.
    Solution:-
    step 1 :- create table items_dup
    as select itid itemid, itemname from items;
    step 2 :- drop table items;
    step 3 :- rename items_dup to items;
    Result:-
    ITEMS table contains columns ITEMID, ITEMNAME

  • How to get the column names of the table into the Dashboard prompt

    how to get the column names of the table into the Dashboard prompt
    Thanks & Regards
    Kishore P

    Hey john,
    My requirement is as follows
    I have created a Rank for Total sales by Region wise i.e RANK(SUM(Dollars By Region)) in a pivot table.
    My pivot table looks like this
    COLUMN SELECTOR: TOTAL US , REGION , DISTRICT , MARKET
    ---------------------------------------------------- JAN 2009          FEB 2009        MAR 2009
    RANK              REGION                  DOLLARS           DOLLARS        DOLLARS DOLLARS
    1 CENTRAL 10 20 30 40
    2 SOUTHERN 10 30 30 70
    3 EASTERN 20 20 20 60
    4 WESTERN 10 20 30 40
    When i select the District in column selector
    Report has to display rank based on Total Sales by District. i.e
    ------------------------------------------------- JAN 2009         FEB 2009       MAR 2009
    RANK             DISTRICT              DOLLARS           DOLLARS        DOLLARS DOLLARS
    for this i need to change the fx of rank i.e RANK(SUM(Dollars By Region)) to RANK(SUM(Dollars By District)) and fx of Region i.e Markets.Region to Markets.District dynamically.
    so , i need to capture column name of the value selected from the column selector and dynamically i need to update the fx 0f RANK & fx of region.
    do you have any solution for this?
    http://rapidshare.com/files/402337112/Presentation1.jpg.html
    Thanks & Regards
    Edited by: Kishore P on Jun 24, 2010 7:24 PM
    Edited by: Kishore P on Jun 24, 2010 7:28 PM

  • How to rename a column name while copying it from another table

    Hi All,
    I am copying rows between two table TableA to TableB
    but I wanted to insert data in he column name (username) in tableA to a column named (NewUser) in tableB
    How do I go about that?
    insert into TableB
    select Username
    from TableA
    Thanks

    If you want to only move username, then just specify the column name for TableB, that is
    insert into TableB(NewUser)
    select Username
    from TableA
    If you want to move all (or some) of the columns while putting Username in a column named NewUser, just list the columns in both the insert into part and the select part, for example
    insert into TableB(NewUser, ColA, ColB, ColC)
    select Username, ColA, ColB, ColC
    from TableA
    Tom

  • How to rename a column name

    dear friends,
    Is there any other way to rename a column without creating another table with the requested colum name and dropping the eariler table after inserting the values from it.

    SQL> desc t2
    Name                                      Null?    Type
    ID2                                                NUMBER
    SQL> alter table t2 rename column id2 to id;
    Table altered.
    SQL> desc t2
    Name                                      Null?    Type
    ID                                                 NUMBERRgds.
    ...but don't forget side effects !
    SQL> create or replace view v2 as select id from t2;
    View created.
    SQL> select status from user_objects where object_name = 'V2';
    STATUS
    VALID
    SQL> alter table t2 rename column id to id2;
    Table altered.
    SQL> select status from user_objects where object_name = 'V2';
    STATUS
    INVALID
    SQL> select * from v2;
    select * from v2
    ERROR at line 1:
    ORA-04063: view "SCOTT.V2" has errorsMessage was edited by:
    dnikiforov

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • How to read the column name of a table from sap system using C#?

    Hi!!
    I am using SAP .NET connector and creating a windows application.
    Now I wanna read the column name when a table name is given....
    Connection is done, but I don't know the code to read the column names alone...
    Can anyone help me with the code??

    fine!!
    So if i give the table name, which the RFC_READ_TABLE function module have, will it run properly? or i wanna change all the codes in order to support RFC_READ_TABLE function module?
    Because from the beginning I was using BAPI_CUSTOMER_GETLIST function, but my client requirement is to use ERP function module RFC_READ_TABLE, he didn't give any table name also..
    This is my code: What I have to change in this???
    ECCDestinationConfig ECCDestination = new ECCDestinationConfig();
                RfcDestinationManager.RegisterDestinationConfiguration(ECCDestination);
                RfcDestination rfcDest = null;
                rfcDest = RfcDestinationManager.GetDestination(a);
                    RfcRepository repo = rfcDest.Repository;
                    IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_GETLIST");
                    IRfcTable addressData = customerList.GetTable("AddressTable"));
                    int j = addressData.Metadata.LineType.FieldCount;
                    for (int i = 0; i < j; i++)
                        RfcElementMetadata metadata = addressData.GetElementMetadata(i);
                        listallcolumn.Items.Add(metadata.Name);
    Message was edited by: Jeswin Rebil

  • How can I change column name in ALV table in WebDynpro ABAP?

    Hi Everyone,
    I have created an ALV table in WebDynpro ABAP. I have created a context node and added the required attributes there - for the ALV display.
    Now I want to change one columnn name of the ALV table.... Currently it is showing the description of the data element, which I don't want to show. I cannot create a new DE only for this purpose.
    Please let me know how can I change the name of the column.
    Regards

    Hi,
    This may help you to define your own column text in the ALV Table of webdynpro.
    see the below code.
    Here 'STATUS_ICON' is the column of the the output display of the ALV Table of webdynpro.
    "change the label of the report.
    DATA: lr_weeknum TYPE REF TO cl_salv_wd_column.
    CALL METHOD l_value->if_salv_wd_column_settings~get_column
    EXPORTING
    id = 'STATUS_ICON'
    RECEIVING
    value = lr_weeknum.
    SET THE LABEL OF THE COLUMN
    DATA: hr_weeknum TYPE REF TO cl_salv_wd_column_header.
    CALL METHOD lr_weeknum->get_header
    RECEIVING
    value = hr_weeknum.
    CALL METHOD lr_weeknum->set_resizable
    EXPORTING
    value = abap_false.
    hr_weeknum->set_prop_ddic_binding_field(
    property = if_salv_wd_c_ddic_binding=>bind_prop_text
    value = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
    set the text of the column
    CALL METHOD hr_weeknum->set_text
    EXPORTING
    value = 'C Form'.
    regarads,
    balu

  • How to read the column name of the Table.

    hi
       I have applied sort functionality to the Table columns. It is working fine but I need to read the table column name before sorting ( On which column user trying to sort ).
       Thank you all,
    Rama...

    Hi Alex
       Thank you very much for your valid input.
    But I am facing one problem here. To get sort functionality I added following logic in WDDOMODIFYVIEW method.
      DATA wd_table TYPE REF TO cl_wd_table.
      CHECK first_time = abap_true.
      wd_table ?= view->get_element( 'TABLE_NAME' ).
      wd_this->table_control ?= wd_table->_method_handler.
      wd_this->table_control->set_key_attribute_name( 'COL_NAME1' ).
    here I hard coded first column name(i.e. COL_NAME1). Is it correct?
      and added following code in SORT ACTION of table i.e.
    wd_this->table_control->apply_sorting( ).
    To get column name I am using the method in SORT ACTION of table which you mentioned but always I am getting  COL_NAME1 only....
    Please help me how can I rectify this...
    Thank you
    Rama

  • How to display the column names of a table in the output

    Hi,
    I want to display the name of the columns of the table without using literals in a abap report.
    EX: Consider the table KNA1
    KUNNR NAME  ADDRESS
    I want to display the column names in the above fashion without using hardcoded write statements.
    Thanking in anticipation

    You can use this FM <b>DDIF_FIELDINFO_GET</b> It gives you all the names related to fields in a table -:)
    Greetings,
    Blag.

  • Rename column name of a table

    Hi Guys,
    I want to rename the column name of a table. Lets say I have table employee:
    SQL> desc emp;
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    STARS VARCHAR2(8)
    I want to change the name of the cloumn name of ENAME to EMPNAME so that structure looks like this:
    SQL> desc emp;
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    EMPNAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    STARS VARCHAR2(8)
    Can anyone tell me any statement or way to solve this problem. Please keep in mind that I will not delete the table or create another column name of EMPNAME and copy the data from ENAME to EMPNAME.
    Regds,
    Debabrata

    ALTER TABLE DEPT2 RENAME COLUMN ENAME TO EMPNAME
    Regards,
    Raj

  • How to modify a column name & How to modify a constraint name

    How to modify a column name?
    How to modify a primary key constraint name if the pk has been referenced by another foreign key?
    Thanks.

    Hi,
    What version of oracle are you using? If it is 9i,
    then you can the command
    alter table <table_name> rename column <column_name> to <new_column>;
    if it is 8i or earlier, you can create a view with the required names.
    hth
    Always post the oracle version and the platform you are using to get better response.

  • How can i replace column name using reciever JDBC adapter on runtime.

    Hi Experts,
    I have a problem with reciever JDBC synario.
    Target Oracle table has columns named 2 bytes Japanese character like "日本".
    Datatype cannot accept 2bytes character as element name.
    So, I would like to how to replace column name on runtime.
    Please tell me.
    Regards,
    Shinya Kawaoge

    Hi Shinya Kawagoe,
    I understand there is a column with two Japanese characters in target database table. Now you want to UPDATE or INSERT data in that table. You do not want to rename the column name in the database table (if you want to rename column, ask the target database admin ).
    As Japanese characters are not allowed in XML Data Type in ESR. You can [Define a SQL_QUERY Statement|http://help.sap.com/saphelp_nwpi711/helpdata/en/44/7b7855fde93673e10000000a114a6b/frameset.htm]. Check the Addres日本s in below code.
    <root>
      <stmt>
        <Customers action="SQL_DML">
          <access> UPDATE Customers SET CompanyName=u2019$NAME$u2019, Addresu65E5u672Cs=u2019$ADDRESS$' WHERE CustomerID='$KEYFIELD$u2019
          </access>
          <key>
            <NAME>Firma</NAME>
            <ADDRESS>Strasse 3 </ADDRESS>
            <KEYFIELD>FI</KEYFIELD>
          </key>
        </Customers>
      </stmt>
    </root>
    Regards,
    Raghu_Vamsee

  • TO Rename a column name

    Hi all,
    I have a table employee with columns
    'employee_id',
    'employee_name'
    ' employee_city' ( Note the spaces before the column name )
    The table is created successfully.
    But i cant to able to retreive the data by specifying the column name..
    eg: select employee_city from employee.
    It throws an error.
    Please send me a solution to reanme the column name, so that it should not contain any spaces at start & end.
    Thanks & Regards,
    Hariharan ST

    Obviously the table was created this way:
    SQL>create table testtab
    "employee_id" number,
    "employee_name" varchar2(100),
    " employee_city" varchar2(100)
    Table created.
    SQL>desc testtab
    Name                                      Null?    Type
    employee_id                                        NUMBER
    employee_name                                      VARCHAR2(100)
      employee_city                                     VARCHAR2(100)Note the double quotes: Columns that are created this way can only be selected using double quotes, too:
    SQL>select employee_city from testtab;
    select employee_city from testtab
    ERROR at line 1:
    ORA-00904: "EMPLOYEE_CITY": invalid identifier
    SQL>select " employee_city" from testtab;
    employee_city
    Chicago
    SQL>This of course is a very bad idea. Dave already showed you how to rename the columns.
    Regards,
    Gerd

  • How to use the column names generated from Dynamic SQL

    Hi,
    I have a problem with Dynamic SQL.
    I have written an SQL which will dynamically generate the Select statement with from and where clause in it.
    But that select statement when executed will get me hundreds of rows and i want to insert each row separately into one more table.
    For that i have used a ref cursor to open and insert the table.
    In the select list the column names will also be as follows: COLUMN1, COLUMN2, COLUMN3,....COLUMNn
    Please find below the sample code:
    TYPE ref_csr IS REF CURSOR;
    insert_csr ref_csr;
    v_select VARCHAR2 (4000) := NULL;
    v_table VARCHAR2 (4000) := NULL;
    v_where VARCHAR2 (4000) := NULL;
    v_ins_tab VARCHAR2 (4000) := NULL;
    v_insert VARCHAR2 (4000) := NULL;
    v_ins_query VARCHAR2 (4000) := NULL;
    OPEN insert_csr FOR CASE
    WHEN v_where IS NOT NULL
    THEN 'SELECT '
    || v_select
    || ' FROM '
    || v_table
    || v_where
    || ';'
    ELSE 'SELECT ' || v_select || ' FROM ' || v_table || ';'
    END;
    LOOP
    v_ins_query :=
    'INSERT INTO '
    || v_ins_tab
    || '('
    || v_insert
    || ') VALUES ('
    || How to fetch the column names here
    || ');';
    EXECUTE IMMEDIATE v_ins_query;
    END LOOP;
    Please help me out with the above problem.
    Edited by: kumar0828 on Feb 7, 2013 10:40 PM
    Edited by: kumar0828 on Feb 7, 2013 10:42 PM

    >
    I Built the statement as required but i need the column list because the first column value of each row should be inserted into one more table.
    So i was asking how to fetch the column list in a ref cursor so that value can be inserted in one more table.
    >
    Then add a RETURNING INTO clause to the query to have Oracle return the first column values into a collection.
    See the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm#sthref2307

Maybe you are looking for