简体   繁体   English

使用 %TYPE oracle 更改表添加列

[英]alter table add column using %TYPE oracle

Can we add a column in a table using the datatype of a column from another table.我们可以使用另一个表中列的数据类型在表中添加一列吗? NO PLSQL.没有 PLSQL。 just a normal SQL query只是一个普通的 SQL 查询

eg as below例如如下

*Table ABC has 3 columns *表 ABC 有 3 列

name varchar2(50)

id number

dob Date

Table XYZ has 2 columns表 XYZ 有 2 列

id number

phone_number number(10)*

Now i want to add another column in Table XYZ With same datatype as NAME of column ABC.现在我想在表 XYZ 中添加另一列,其数据类型与 ABC 列的名称相同。

but the below command is not working但以下命令不起作用

alter table XYZ ADD MOTHERS_NAME ABC.NAME%TYPE;

Sorry that facility does not exist.抱歉,设施不存在。

You could query USER_TAB_COLS to determine the data type of the source column and dynamically build the ALTER TABLE command, but that still does not do anything like keep them in sync.您可以查询 USER_TAB_COLS 来确定源列的数据类型并动态构建 ALTER TABLE 命令,但这仍然没有做任何事情,比如让它们保持同步。 It would just be a syntactical convenience.这只是一种语法上的便利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM