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

Similar Messages

  • 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.

  • 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 can we improve the performance while fetching data from RESB table.

    Hi All,
    Can any bosy suggest me the right way to improve the performance while fetching data from RESB table. Below is the select statement.
    SELECT aufnr posnr roms1 roanz
        INTO (itab-aufnr, itab-pposnr, itab-roms1, itab-roanz)
        FROM resb
        WHERE kdauf  = p_vbeln
        AND   ablad  = itab-sposnr+2.
    Here I am using 'KDAUF'  & 'ABLAD' in condition. Can we use secondary index for improving the performance in this case.
    Regards,
    Himanshu

    Hi ,
    Declare intenal table with only those four fields.
    and try the beloe code....
    SELECT aufnr posnr roms1 roanz
    INTO  table itab
    FROM resb
    WHERE kdauf = p_vbeln
    AND ablad = itab-sposnr+2.
    yes, you can also use secondary index for improving the performance in this case.
    Regards,
    Anand .
    Reward if it is useful....

  • 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

  • Change sales area while copying contract from another contract

    Hello Gurus,
    I am copying sales contract from another sales contract. I have maintained copy control accordingly.
    Here i want to change sales area of being created sales area.
    Ex.
                                                 Sales area
    Reference contract             1000-10-10
    New Contract                       2000-10-10
    How can i control this ??...Where and what change should i made in copy control to achieve this ?
    Thanks in advance...
    Regards,
    Tarpan Vadaliya

    Thanks Kapil for your input.
    But still my question is not answered completely.
    My requirement in simple that i want to create a contract with reference to another contract but in different sales area. My customer will be remain same. So it does not relevant whether i use routine 001 or 002.
    I had tried to create with both routine but i am not getting succeed.  I had also removed below mention code from routine and tried but not succeed.
    IF HVBAK-VKORG NE VBAK-VKORG.
          MESSAGE E007 WITH HVBAK-VKORG VBAK-VKORG.
        ENDIF.
    Is the dist. channel the same in both reference and target?
        IF HVBAK-VTWEG NE VBAK-VTWEG.
          MESSAGE E011 WITH HVBAK-VTWEG VBAK-VTWEG.
        ENDIF.
    Is the division the same in both reference and target?
        IF HVBAK-SPART NE VBAK-SPART.
          MESSAGE E012 WITH HVBAK-SPART VBAK-SPART.
        ENDIF.
    Still waiting for helpful solution...
    Tarpan

  • How to make validation in Bean and select value from another table

    I want to know how to select data from table in backing bean according to primary key i have
    the problem is that
    i have a table Employee_Salary contains Employee ids and their salary
    Empoloyee_Salary table
         Employee_ID      Number
         Employee_salary Number
    And Another table Called Employees
    Employees table
         Employee_ID     Number
         IsManager Varchar2 its value is [*Yes or NO*]
    and other columns that i don't care about this table
    i have on a jsff page an <af:table> this table is editable this is the Empoloyee_Salary table
    *i want to check before save or after insert if this employee is Manager [from Employees tabke(yes or no)] the salary*
    cannot be less that 100
    i want to know how to make this how to select the value from employees table according to the id i have in the employee_salary table how to make this and make this validation
    i have to select IsManager from Employees Table to see if this manager or no
    i want to know how to make this in a bean
    i use jdeveloper 11g
    and my project is ADF Fusion project
    and the page that have the Emplpyee_Salary table is JSFF
    thanks in advance

    You might want to write this code in a validator on the entity object if it should apply from every screen.
    If you want to access view objects from a backing bean the basics are here: http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918

  • Template error while copying page from another application

    I am copying a page from one application to another within the same workspace. The page I am copying has several customized template that it uses. When I copy the page to the other application all goes well until I get to the step of assigning the Templates. Instead of seeing the list of templates used and being able to change them for the new page to match with the page i am copying, i get an error in the Templates area that says:
    report error:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Anyone else run into this? Is this because of the number of templates? I have added several new customized templates. The pages all work ok, its just when i am trying to copy a page from one application to another.
    Thanks,
    John

    I'm seeing this behavior as well, but in the Authorization Schemes & LOV sections of the copy. I can continue with the page copy, but the LOV & Scheme information is lost and needs to be manually re-entered. Would love to get a fix for this!

  • How do I reference columns in a report query from another report query?

    In Apex 3.1 it is possible to generate a report on more than one query. I have read that these queries can be correlated, but I cannot find how in the documentation.
    I go the Shared Components and create a new Report Query:
    select * from dept
    Then I click Add Query and I add:
    select * from emp
    How do I correlate these two queries (I want to join emp.deptno to dept.deptno) and have a nice hierarchicle XML-file.
    Is it possible in Apex 3.1?
    Dik Dral

    Dik,
    This type of query can't be build. The two queries are independent, you can't reference values in the first query from the second query. However you can reference page and application items - which won't help you all that much with this scenario though. You could also try combining the two queries into one, and then take care of the proper presentation in your template.
    Regards,
    Marc

  • 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 to pull only column names from a SELECT query without running it

    How to pull only column names from a SELECT statement without executing it? It seems there is getMetaData() in Java to pull the column names while sql is being prepared and before it gets executed. I need to get the columns whether we run the sql or not.

    Maybe something like this is what you are looking for or at least will give you some ideas.
            public static DataSet MaterializeDataSet(string _connectionString, string _sqlSelect, bool _returnProviderSpecificTypes, bool _includeSchema, bool _fillTable)
                DataSet ds = null;
                using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                    try
                        _oraconn.Open();
                        using (OracleCommand cmd = new OracleCommand(_sqlSelect, _oraconn))
                            cmd.CommandType = CommandType.Text;
                            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                                da.ReturnProviderSpecificTypes = _returnProviderSpecificTypes;
                                //da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                                if (_includeSchema == true)
                                    ds = new DataSet("SCHEMASUPPLIED");
                                    da.FillSchema(ds, SchemaType.Source);
                                    if (_fillTable == true)
                                        da.Fill(ds.Tables[0]);
                                else
                                    ds = new DataSet("SCHEMANOTSUPPLIED");
                                    if (_fillTable == true)
                                        da.Fill(ds);
                                ds.Tables[0].TableName = "Table";
                            }//using da
                        } //using cmd
                    catch (OracleException _oraEx)
                        throw (_oraEx); // Actually rethrow
                    catch (System.Exception _sysEx)
                        throw (_sysEx); // Actually rethrow
                    finally
                        if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                            _oraconn.Close();
                }//using oraconn
                if (ds != null)
                    if (ds.Tables != null && ds.Tables[0] != null)
                        return ds;
                    else
                        return null;
                else
                    return null;
            }r,
    dennis

  • How to Rename the technical name and description of an infocube?

    Hi,
    How to Rename the technical name and description of an infocube?
    Thanx in advance,
    Ravi.

    Ravi,
    You cant change the Technical name of the cube but you can change the description of the Cube. If you want to have a Cube with the same properties and with different Techname and Description better you do copy from the base cube and rename as per your requirement.
    Regards,
    Gattu.

  • 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

  • Tomcat running under apache

    Hi All, I want to be able to run my tomcat3.3.1a under apache webserver, and i klnow i have to use mod_jk. The problem i am having is that my tomcat is not producing the mod_jk.conf_auto file. I have even added the apacheconfig directive to server.xm

  • Download file in txt format

    Hi, Im using Forms 6i, The output data is not spliting into lines by line .in between the lines there is a small box.If i open the same file in word itis spliting line by line. PROCEDURE do_based_customers (p_org_id in number,p_user_id in number,p_in

  • TDS While making outgoing payment

    Hi, How to deduct TDS while making outgoing payments? Pls help in this regards Thanks & Regards Suresh Kannan Edited by: Marc Riar on Jan 31, 2008 2:18 PM Edited by: Marc Riar on Feb 15, 2008 9:36 AM

  • UCCX HA failover, what is sync'ed?

    Hi When setting up UCCX HA the configuration is sync'ed with the heatbeat and if the primary failes the slave takes over. I have found information about the exchange of configuration but i havent found information about what happens with the sessions

  • Dynamic version tracking

    Is anyone aware of a way to create PDF documents which dynamically check online to ensure the user is working from the latest version? As an example: I'm creating a training manual which will frequently be updated. It would be good if when the docume