473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ORACLE10: Rename column that has keyword name

115 100+
Hi,

I have a table that has a column with name "comment" in it. I think that "comment" is an oracle keyword so i would like to rename this column.

when i use the syntax "alter table tablename rename column comment to somethingbetter" i get error invalid identifier. I also tried dropping the column altogether and creating a new one but i get the same error on drop.

I tried creating a new table for an example to post here but i get the same error on "comment".

I don't know how this column got created in the first place, but after the trouble im having here I really think this column needs to be renamed to avoid future problems.

Any ideas?
Jun 23 '08 #1
4 12623
Dave44
153 100+
ya thats a tough one, i cant create a table with that column name to try and test some theories; keeps failing with invalid identifier.

Could you try creating a new table as select <columns> from old_table and alias the comment column with something else? Then use dbms_redefinition to swap all the other objects on the old table to the new one (like indexes and such).
Jun 24 '08 #2
amitpatel66
2,367 Expert 2GB
The column should have been created using double quotes.

Check this:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. SQL> create table t("comment" varchar2(10));
  4.  
  5. Table created.
  6.  
  7. SQL> select "comment" from t;
  8.  
  9. no rows selected
  10.  
  11. SQL> insert into t values('1234');
  12.  
  13. 1 row created.
  14.  
  15. SQL> commit;
  16.  
  17. Commit complete.
  18.  
  19. SQL> select "comment" from t;
  20.  
  21. comment
  22. ----------
  23. 1234
  24.  
  25. SQL> alter table t rename column "comment" to abc;
  26.  
  27. Table altered.
  28.  
  29. SQL> select abc from t;
  30.  
  31. ABC
  32. ----------
  33. 1234
  34.  
  35. SQL> drop table t;
  36.  
  37. Table dropped.
  38.  
  39. SQL> 
  40.  
  41.  
Jun 24 '08 #3
ShadowLocke
115 100+
Sorry for going quite. What I had ended up doing as i was in a rush was creating a new table and inserting the data into it then just dropping the table.

But, I had a co-worker that just today made the same mistake. (created a column named comment) We tried the syntax given below and it worked perfect.

that is:
Expand|Select|Wrap|Line Numbers
  1. SQL> alter table t rename column "comment" to abc;
ftw

Thanks!

The column should have been created using double quotes.

Check this:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. SQL> create table t("comment" varchar2(10));
  4.  
  5. Table created.
  6.  
  7. SQL> select "comment" from t;
  8.  
  9. no rows selected
  10.  
  11. SQL> insert into t values('1234');
  12.  
  13. 1 row created.
  14.  
  15. SQL> commit;
  16.  
  17. Commit complete.
  18.  
  19. SQL> select "comment" from t;
  20.  
  21. comment
  22. ----------
  23. 1234
  24.  
  25. SQL> alter table t rename column "comment" to abc;
  26.  
  27. Table altered.
  28.  
  29. SQL> select abc from t;
  30.  
  31. ABC
  32. ----------
  33. 1234
  34.  
  35. SQL> drop table t;
  36.  
  37. Table dropped.
  38.  
  39. SQL> 
  40.  
  41.  
Jul 28 '08 #4
liza1
4
First you add a new Coloum.To add a column named "comment 1" in the table by using Alter command.

Syntax: ALTER TABLE table_name
ADD column_name datatype

and then drop coment coloum in your table by using drop command.

Syntax: ALTER TABLE table_name
DROP COLUMN column_name

I think this will help you. To know more about Oracle so there are number of nice video Tutorils on

http://codervods.com/

Thanks
Aug 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: TroelsM | last post by:
Hi there ! I am trying to rename a column i Access Set Conn1 = Server.CreateObject("ADODB.Connection") Conn1.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &...
3
by: mfyahya | last post by:
I have a table with three text columns and one time column (say text1, text2, text3, and time). I wrote a query to select the rows where any of the text columns contains a certain keyword: select...
3
by: D. Dante Lorenso | last post by:
I just ran into a dump/restore problem with a bigserial column on a renamed table. BIGSERIAL columns when created will automagically create the sequence also. The sequence name is derived from...
2
by: mike_dba | last post by:
I am running V9 FP2 on DPF. I understand that V9 LUW now lets you rename a column. I can't seem to get the sytax right. Can anyone point me to what is wrong? db2 "ALTER TABLE myschema.mytable...
4
by: ganeshshegde | last post by:
How to rename the column? i entered "alter table student_19104 rename student_marks to stud_marks" But it's giving error "missing PARTITION or SUBPARTITION keyword "
0
by: aberton | last post by:
Hi all, I am having major performance issues between my linked server and an Oracle10 db. I have created a number of views in my SQL Server database which map to corresponding Oracle tables via a...
0
by: aberton | last post by:
Hi all, I am having major performance issues between my linked server (SQL Server) and an Oracle10 db. I have created a number of views in my SQL Server database which map to corresponding Oracle...
1
by: Gladiator | last post by:
Hi Team , Can some one tell me why we dont we have a DROP column or rename a column command in DB2 ? I Have a very Huge table and need to rename a column . The only option i have to do to rename...
1
by: Darrenovic | last post by:
Hi, I'm using Vista and i have some issue that i need to know in order to do it efficiently in Ms SQL server 2008. I have an excel/word file with all the tables name in a column along their...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.