[英]Oracle 12c - how to cast from one column to another
I have table 't1' in oracle 12c with one column: 'id1 varchar2 (5 BYTE)' 我在Oracle 12c中具有一列的表't1':'id1 varchar2(5 BYTE)'
How to create another column 'id2 number(5,0)' in the same table and copy all the records from id1 column to it? 如何在同一表中创建另一列“ id2 number(5,0)”,并将所有记录从id1列复制到该表中?
(values in column 'id1' are numeric by the way) (顺便说一句,“ id1”列中的值是数字)
ALTER TABLE T1 ADD (ID2 NUMBER(5, 0));
and 和
UPDATE T1 SET ID2 = ID1;
Implicit conversion between VARCHAR2 and NUMBER should handle the type difference, assuming all the characters in ID1 are in the range 0-9. 假定ID1中的所有字符都在0-9范围内,则VARCHAR2和NUMBER之间的隐式转换应处理类型差异。
Best of luck. 祝你好运。
First add column in the table 首先在表格中添加列
alter table table1 add(id2 number(5,0));
and then just copy existing column in new column 然后只需将现有列复制到新列中
update table1 set id1=id2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.