2012-07-07 37 views
2

我的表名userdetails如何将列插入到现有表中?

我想以后location列插入新列mob

我尝试使用代码

alter table userdetails 
add mob varchar2(10) after location; 

但其示值误差

ORA-01735:无效的ALTER TABLE选项

请帮助我。

我使用的是oracle10g。

+1

您可以使用此解决方案: http://stackoverflow.com/questions/5391280/如何插入一列在特定位置在甲骨文没有下降和记录 – vtokmak 2012-07-07 09:52:11

+0

是啊,但从谷歌搜索我得到了这段代码,显示错误 – Prashobh 2012-07-07 09:57:14

+4

你不能创建一个新的列*在给定列之后 - 新列总是添加到表的末尾。另外:在关系数据库中,列的顺序无论如何都是绝对不相关的。 – 2012-07-07 10:02:01

回答

4

尝试摆脱

alter table userdetails add (mob varchar2(10)) 
+0

不,我想在列位置后面添加mob列。这将在最后创建列 – Prashobh 2012-07-07 09:58:22

+2

Oracle只允许将列添加到现有表的末尾。你可以在这里看到非标准方法http://www.orafaq.com/faq/how_does_one_add_a_column_to_the_middle_of_a_table – yital9 2012-07-07 10:00:00

+0

谢谢你的链接,在MySQL中只有语法是有效的,谢谢 – Prashobh 2012-07-07 10:07:55

1

“后” 有没有 “位置后”。该语法无效。

你可能走以下路线: 只需将mob varchar添加到userdetails即可。 它将被添加在表格的末尾。 而且你仍然可以查询它。 ALTER TABLE的UserDetails ADD(暴徒VARCHAR2(10))

要得到表结构你想:

// 1) rename the table 
rename userdetails to userdetails_old; 

// 2) recreate the table with your wanted structure 
// Note that the selection order decides about the table structure. 
create table userdetails 
as 
select a as a 
    , b as b 
    , location as location 
    , mob as mob 
    , c as c 
from userdetails_old; 

// 3) check what you did 
desc userdetails; 

// 4) before dropping your old table 
drop table userdetails_old; 
+0

没问题。但接受的答案不回答你的问题:) – 2012-07-19 16:38:55

相关问题