简体   繁体   English

Oracle 12c-如何从一列转换为另一列

[英]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.

相关问题 如何在 Oracle 12c 中基于一个整数列(每个值 = 1 个分区)创建分区表? - How to create partitioned table based on one Integer column (each value = 1 partition) in Oracle 12c? Oracle 12c-使用另一个表中的序列插入重复项 - Oracle 12c - insert duplicates with sequence from another table 如何在Oracle 12c中使用多个数据更新单个列 - How to update a single column with multiple data in oracle 12c SQL(Oracle 12c):如何从另一个选择语句(嵌套?/子查询?)中选择结果 - SQL (Oracle 12c): How to select results from another select statement (nesting?/sub--query?) 如何在 Oracle SQL 中将多个列值组合成单个值作为逗号分隔的字符串(Oracle Forms 12c) - How to combine more than one column values into single value as a comma separated string in Oracle SQL (Oracle Forms 12c) 如何在oracle 12c中创建用户 - how to create a user in oracle 12c Oracle 12c:如何将现有主键列修改为标识列? - Oracle 12c: How can I modify an existing primary key column to an identity column? Oracle 12c-使用另一个表中的值在表中插入值 - Oracle 12c - Insert values in a table using values from another table 在Oracle 12c中的多行上串联一列 - Concatenating a column over multiple rows in Oracle 12c Oracle 12c column_name不一致 - Oracle 12c column_name inconsistency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM