How to rename a column
i cannot rename a column in a table;
i tried so many sql statements but with no results;
i use the following:
alter table tablename rename column old_column to new_columnname;
In other case you can create a view on that table to rename the columns like
SQL> select empno, ename, job from scott.emp;
EMPNO ENAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
EMPNO ENAME JOB
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.
SQL> create or replace view emp_vw as select empno as emp_no, Ename as Employee_Name, job from scott.emp;
View created.
SQL> select * from emp_vw;
EMP_NO EMPLOYEE_NAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
EMP_NO EMPLOYEE_NAME JOB
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.
SQL>
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?
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 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.
jingThere 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 -
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 rename the column field names
hello guys,
i am retrieving my field names from the database and i view it thru HTML.
When i view it,the column names are those which are given while creating tables.
Ex..
fname,lname,phno,
i want it as First Name,Last Name,Phone Number etc ...<%
try {
stmt = con.createStatement();
sql="SELECT fname, lname, gender, email,phnum,sartweblink, sartaddress1, sartaddress2,sartcounty, country,sartpostcode,dob FROM Artist where artistid='" + sartid + "'";
rs=stmt.executeQuery(sql);
rsmd=rs.getMetaData();
int colcount=rsmd.getColumnCount();
for(i=1;i<=colcount;i++)
%>
<tr><td width="200"><FONT face=verdana size=2><%= rsmd.getColumnName(i)%>
<%
%> </FONT>
<font face=verdana size=2>
<% while(rs.next())
fname=rs.getString("fname");
lname=rs.getString("lname");
gender=rs.getString("gender");
email=rs.getString("email");
phnum=rs.getInt("phnum");
weblink=rs.getString("sartweblink");
address1=rs.getString("sartaddress1");
address2=rs.getString("sartaddress2");
county=rs.getString("sartcounty");
country=rs.getString("country");
postcode=rs.getString("sartpostcode");
dob=rs.getString("dob");
%>i make use of metadata..
can anyone tell me how to do this..
thanks in advancewhy not use alias:
your query is
SELECT fname, lname, gender, email
and will be:
SELECT fname FIRSTNAME, lname LASTNAME, gender GENDER, email EMAILADDRESS -
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
ThanksIf 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 -
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 STObviously 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 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 -
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 resolve unresolved column error when we change column name in BMM Layer and removed alias in presentation layer
Looks like the presentation column got Alias before your BMM changes, so in your case renaming logical column and deleting alias is not good to go.
Keep Alias -
How do I restore column headings in Response table after accidently deleting them? Undo doesn't work (only seems to go back one level). I also have so many headings I won't be able to type them in manually!
With the help of information from user, ptressel, in [https://support.mozilla.org/en-US/questions/1032154#answer-673322 a post here about the existence of sessionstore.js when version 33 was released], I was able to easily recover my tabs and tab groups as follows:
# close Firefox and, perhaps, allow a few seconds (30s?) for any final closing of files;
# check to see if you have a sessionstore.js file in your profile folder, named like the one I documented in my original post above;
# if it is not timestamped prior to the discovery of your problem, open the sessionstore-backups folder;
# check if the recovery.js file is suitably timestamped and, if not, the recovery.bak.
# At this point, you are likely to find that none of them are prior to your problem occuring. If so, open your backups of this folder and go through steps 2-4 to find a file prior to your problem occuring.
# When you find a file, copy it to the root of your current profile folder and name it, "sessionstore.js"
# Open Firefox. Mine opened up as desired.
This is a Windows solution. Sorry I can't comment on other platforms, but I'd bet that as this is just a file copy and renaming, it is likely the same.
For Windows users, you may find you need to sign out and login as an administrator in order to access the backups. You need not logoff your standard account, but do have Firefox closed as described above.
Hope that helps. -
How to add dynamic column in jfreereport
hi,
i am working on a project aboit accounting package.
i had created a report in jfreereport .. buti am facing the problem of dynamic column addition in that..
i have to create the number of column as per user given range that will from 2 to 365
i had generated column for that
that should be like
1 - 5 , 6 -10 , 11 - 15 , etc...
how can i represent that alll column in print preview i can't represent that report in horizontal fashion . is there any way to display it ..
this report has no bound in horizontal or verticle means i have any number of rows or columns..
pls help.
kamleshhi,
that means u have fixed columns right? ie 5 columns in a report
if it write, than u can find out how u can rename the columns with exiting
one.
that means while runing report u have to pass all the 5 columns to report
instead of the exiting columns (ie rename the columns that u want add
columns)
u have to search in code for renaming in the code ie jfreereport package.
i think u understood.
daya -
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 KawaogeHi 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 -
Reg:How to delete the column in table control also from database table.
Hi Experts,
Once again thank u all for giving the responses.
one more doubt is how to delete the columns of table control and also the record shold delete from ztable.
With Regards,
Saroja.P.Hi,
If you want to delete the rows in the table control and simultaneously delete it from the database table, then you can implement a 'DELETE' functionality specific to your table control. Have a MARK field (you will find that in the screen attributes of the table control -> give a name for the MARK field, you will find an additional MARK column at the beginning of your table control). You can check whatever rows you want to delete from the table control, call the delete module.
"This portion of code inside the LOOP...ENDLOOP.
IF sy-ucomm eq 'F_DELETE'.
gt_itab2-check = mark. " Store the MARK field status into your internal table's correspoding field 'check'
MODIFY gt_itab INDEX tabcontrol-current_line.
ENDIF.
iF sy-ucomm eq 'DELETE1'.
DELETE gt_itab WHERE check eq 'X'. "Your internal table does not have rows that you want to delete
ENDIF.
Now you can modify your database table using the MODIFY statement.
MODIFY ZDB FROM TABLE gt_itab. -
How to print all columns in one page
Hi,
Can anybody explain me how to print all columns in one page.we have around 15 to 20 columns for 4 reports and all these reports are build on one multiprovider.we are using BW 3.5.
Can anyone explain me how to print ALL COLUMNS IN ONE PAGE .currently they are getting all columns in 2 to 3 pages. They are using PORTAL to run the reports here.
Is it possible to do by customizing Webtemplate or by macros in Workbook.Please help me
Edited by: kotha123 on Oct 11, 2010 5:58 PMHi,
Your best bet is to use a workbook template or else Excel to pdf option...Thanks
Maybe you are looking for
-
# I formatted my desktop # I install Firefox # I tried the Firefox sync option so I can restore my stuff # And it's asked me for a username & password, So I used my username and password but I stopped when it asked me for a recovery key that I don't
-
Performing lookup in XI to access file stored in link provided in IDOC
Hi All, Can anyone please tell me if the below mentioned requirement is feasible and if yes how it can be done. Requirement is to send eg - Work Order (Idoc type ORDER01) message to thirdparty via PI . The workorder send would have a url
-
How to find out the current screen resolution/width in webdynpro.
HI, Can any one please tell me how to get the screen resolution in webdynpro? Regards -Sandip
-
Share objects between two repositories
hello, How can I use the objects in a another designer/2000 repository in my repository? Is it possible? Thanks in advance.
-
Sending attatchments....
hi all, Im developing a webmail and i've seen on the net about how to send an attatchment in mail..i found this..... try { String text="This is the file attachment"; // create a message Message msg = new MimeMessage(mailsession);