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
Similar Messages
-
Can i rename column name of a table. If so how to do it????
before 9i
Renaming a column in table:
==========================
This is possible by updating the "name" column of the col$. To reflect this
change in the system views, run catalog.sql and catproc.sql.
Here is an example:
SQL> create table test(
x number,
y varchar2(10),
z varchar2(10));
SQL> insert into test values (12,'Child','BLUE');
SQL> insert into test values (34,'Mens','BROWN');
If you wanted to rename column "x" as column "x1" then do the following.
The first step is to identify the object number for the table (as SYS):
SQL> select obj# from obj$
where name='TEST' and owner#=9;
OBJ#
======
58217
Now identify the column numbers for the table:
SQL> select obj#, col#, name from col$ where obj#=58217;
OBJ# COL# NAME
58217 1 X
58217 2 Y
58217 3 Z
To change the name, a simple update statement will suffice:
update col$ set name='X1'
where obj#=58217 and col#=1;
To reflect the change in system views, run catalog and catproc (unix) eg:
svrmgr> @$ORACLE_HOME/rdbms/admin/catalog
svrmgr> @$ORACLE_HOME/rdbms/admin/catproc
Now when a describe of the table is done:
SQL> desc test;
Name Null ? Type
X1 NUMBER
Y VARCHAR2(10)
Z VARCHAR2(10)
Similarly, selecting from the table and querying views such as
DBA_TAB_COLUMNS shows the new column name.
NOTE: Before changing column names, drop any indexes,
foreign keys and primary constraints that might be on
the column. These can be re-created later. -
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?
thanksIn 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 column name of table?
Hello...
How to rename column name of table?
The column have data.
Thanks.
Martonio.The following should work in 9i release 2 and above.
SQL> create table mytable(col1 varchar2(2),
2 col2 date);
Table created.
SQL> insert into mytable values('t1',sysdate);
1 row created.
SQL> select * from mytable;
CO COL2
t1 30-NOV-04
1 row selected.
SQL> desc mytable
Name Null? Type
COL1 VARCHAR2(2)
COL2 DATE
SQL> alter table mytable rename column col2 to mydate;
Table altered.
SQL> desc mytable
Name Null? Type
COL1 VARCHAR2(2)
MYDATE DATE
SQL> select * from mytable;
CO MYDATE
t1 30-NOV-04
1 row selected.
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.3.0 - Productionhttp://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/wnsql.htm#972698 -
Column names from another table
Hi All,
I have a scenario where i need to get names of a column from another table
for eg,
Table EMP
EmpNo EmpName EmpContact EmpPhone
1 xyz [email protected] 345
2 abc [email protected] 897
3 ttp [email protected] 345
The column names of this table can be configurable from some other place and its value is stored in another table like
Table Config (2 Columns)
Column_Name Value
EmpName First name
EmpContact Email
EmpPhone Mobile
Now i want to fetch the values from Emp table but with column headers that are changed and have a value in Config table.
If a column name is not there in config table then the original column name should come.
As shown below
EmpNo First name Email Mobile
1 xyz [email protected] 345
2 abc [email protected] 897
3 ttp [email protected] 345
Another eg, If EmpName is not changed and entered in second table , then i want to have the same name as the original EMP table has as shown below.
EmpNo EmpName Email Mobile
1 xyz [email protected] 345
2 abc [email protected] 897
3 ttp [email protected] 345
In other words something like this,
select empno,
EmpName as (select value from config where column_name=EmpName),
EmpContact as (select value from config where column_name=Empcontact),
EmpPhone as (select value from config where column_name=EmpPhone)
From EMP
Can some one please help me in providing a solution for this.
Edited by: 941386 on May 30, 2013 6:20 AMUnfortunately, I think this is a job for dynamic sql ...
Build your "query" first:
(note this won't work "as is", fix the syntax - but you get the idea.)
lv_str := 'select empno,
EmpName as ' || (select value from config where column_name=EmpName) || ',
EmpContact as ' || (select value from config where column_name=Empcontact) || ',
EmpPhone as ' || (select value from config where column_name=EmpPhone) || '
From EMP;';
execute immediate lv_str;Not sure if there's a better way or not.
Only other way I can think of is to leverage the way UNION [ALL] works.
So the following query:
select a, b, c from dual
union all
select d, e, f from dual
/returns data in columns "named" : "a, b, c"
Effectively renaming columns d, e, f. You just need to turn your data on edge in that first query, then throw out the rows (I don't know how to get it to work, but perhaps somebody else does?)
[edit]
another thought is create a view over top of the table, query that view, then drop the view :P
that would work nicely - avoid the dynamic SQL. shrug
[edit]
Edited by: Greg.Spall on May 30, 2013 9:37 AM -
DEAR FRIENDS,
I HAVE DATAS IN A COLUMN AND WANT TO RENAME IT WITHOUT CREATING ANOTHER TABLE AND INSERTING THE DATAS INTO IT. HOW TO DO THAT?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)
SQL> alter table emp rename column ename to employee_name ;
Table altered.
SQL> desc emp
Name Null? Type
EMPNO NOT NULL NUMBER(4)
EMPLOYEE_NAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL> -
How to select even the column names of a table?
Hello All,
Is there a way to select even the column names of a table in the select statement?
My select from a table (say X) is in a SQL* Plus script that gets invoked by application tier and displays data in the application tier window. User's can then copy the data into a spreadsheet and do their processing. However, I need to give them the column names too along with the data.
Thanks,
ChiruIf there is a middle tier that is selecting and
displaying the data, and that's what the users are
copying from, the middle tier would have to address
its presentation of the data to allow users to
include column names. If this is a common task, the
application should probably be modified to give users
the option of downloading the data in a spreadsheet
directly rather than forcing them to copy and paste
data.Thanks for the reply.
The users don't have to copy paste. The application tier has an options in the "Tools" menu item which allows them to copy the entire output to a file (in my case a txt file which is a pipe delimited). Then they have to do text to columns to get the data into each column of the spreadsheet. I could have directly called the stored procedures from the application tier and created ".csv" files and FTP'd them to the user's folders. However, I am having to go this round about because, I am not getting enough support from the LAN team in FTP'ing etc.
OK I'll think of another workaround.
Thanks,
Chiru -
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 SevalkarIf 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 -
What is the use of Position Column Name in USER_CONS_COLUMNS Table
Please let me know the purpose of POSITION Column Name in USER_CONS_COLUMNS Table.
Example :
Created this below Table having two constraints 1.Primary Key 2.Check Constraint
CREATE TABLE A(ID NUMBER PRIMARY KEY,NAME VARCHAR2(30),SAL NUMBER CHECK (SAL > 0))
When i execute the below query
SELECT POSITION,CONSTRAINT_NAME FROM USER_CONS_COLUMNS WHERE TABLE_NAME = 'A'
it displays the data :
POSITION CONSTRAINT_NAME
1 SYS_C005488
SYS_C005487
Only for the first record it displays the POSITION but not for the second row.
Kindly help me on this.SQL> CREATE TABLE A(
2 ID1 NUMBER
3 , ID2 NUMBER
4 , NAME VARCHAR2(30)
5 , SAL NUMBER CONSTRAINT A_SAL_POSITIVE CHECK (SAL > 0)
6 , CONSTRAINT A_PRIMARY_KEY PRIMARY KEY (ID1, ID2)
7 )
8 /
Table created.
SQL> SELECT CONSTRAINT_NAME, POSITION, COLUMN_NAME
2 FROM USER_CONS_COLUMNS
3 WHERE TABLE_NAME = 'A'
4 ORDER BY CONSTRAINT_NAME, POSITION
5 /
CONSTRAINT_NAME POSITION COLUMN_NAME
A_PRIMARY_KEY 1 ID1
A_PRIMARY_KEY 2 ID2
A_SAL_POSITIVE SALA primary key constraint can have multiple columns - the position shows the order the columns are in the primary key definition (and thus also in the pk supporting index.)
A check constraint does not have any such ordering of the columns involved, so therefore position is null. -
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 -
Set the column name of a table in a list box
is there any code to set the column name of a table in a list box at oracle devloper 6i?
pls help.I dont want to go for pl/sql . It should work any table.You want Dynamic SQL without using PL/SQL? Tricky. I'm sure there's a possible way using some very complex and convoluted XML functionality of SQL but in reality you are asking for something that isn't natural to SQL queries, especially if you are expecting a dynamic number of columns to be produced for each row of data. SQL expects a table structure, including output formats, to be a defined number of columns with any number of rows, not a defined number of rows with any number of columns.
Perhaps if you explain why you need this sort of functionality then we may be able to offer a better solution.
;) -
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 PHey 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 -
Characters not allowed in column names in Siebel table
Hello,
I am trying to find out the characters or symbols which are not allowed to be a part of column names in Siebel tables. For instance, I checked and found out ( and ) along with all numbers and alphabets are allowed to be part of column name of tables in Siebel. I am looking for some character or character sequence which are not allowed to be used as part of column names.
RegardsWhy do you need to know?
Here you can read something for Oracle: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm -
How to know primary key column name form a table name in sql query
Suppose I only know the table name. How to get its primary key column name from the table name?
ThanksViews don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
You can select the text of the view in question from user_views. -
List of common column name in a table
I had an urgent request to check for common column name in a table. The table that I can currently have select privelge is ALL_TAB_COLUMNS. I need to list all column_name, table_name, and owner. Thanks.
SQL> sho user
USER is "SCOTT"
SQL> select * from tab
2 where tname like '%EMP';
TNAME TABTYPE CLUSTERID
EMP TABLE
V_EMP VIEW
SQL> select distinct owner, table_name
2 from all_tab_columns
3 where table_name like '%EMP';
OWNER TABLE_NAME
SCOTT EMP
SCOTT V_EMP
SYS EXU7COL_TEMP
SYS EXU8COL_TEMP
SQL>
Maybe you are looking for
-
Ipod is visible in Itunes only once
I have a brand new ipod. After installation of ITunes and ipod updater, I can plug the ipod in through a USB 2.0 port and see the ipod in Itunes and put all of the music files I want on it. After I unplug the ipod and try to plug it back in, it is no
-
I've been having random shutdowns
Hello, I've been having random shutdowns for a while now. It is completely random and sometimes the screen will flicker when it shuts down and sometimes not. Here is the report. Interval Since Last Panic Report: 14960 sec Panics Since Last Report:
-
Changing web gallery presets (like background colour) and saving fields
Hello all-can this be done and, if so, how? I want to change the "Stock" preset (with a black BG) so that it features a dark grey instead. As well, I want Aperture to remember my studio name, etc.; for now, all that is remembered is copyright info. I
-
After latest security update my MacBook is not finding any network and I think is not really turning wifi on. Has anyone encountered similar problem?
-
SLR - transaction response time for all appl. servers together
Hi, we want to have in SLR response time for defined transaction. We have activated necessary steps for monitoring transactions, started CPH and we can see in SLR average response times. We have several application servers and we want to have in SLR