How to modify data type in Oracle with existing rows in table(如何使用表中的现有行修改 Oracle 中的数据类型)
问题描述
如何在不删除表数据的情况下将列的数据类型从 number 更改为 varchar2?
How can I change DATA TYPE of a column from number to varchar2 without deleting the table data?
推荐答案
你不能.
但是,您可以使用新数据类型创建新列、迁移数据、删除旧列并重命名新列.类似的东西
You can, however, create a new column with the new data type, migrate the data, drop the old column, and rename the new column. Something like
ALTER TABLE table_name
ADD( new_column_name varchar2(10) );
UPDATE table_name
SET new_column_name = to_char(old_column_name, <<some format>>);
ALTER TABLE table_name
DROP COLUMN old_column_name;
ALTER TABLE table_name
RENAME COLUMN new_column_name TO old_coulumn_name;
如果你的代码依赖于表中列的位置(你真的不应该有),你可以重命名表并使用表的原始名称在表上创建一个视图,以公开按照您的代码预期的顺序排列列,直到您可以修复该错误代码.
If you have code that depends on the position of the column in the table (which you really shouldn't have), you could rename the table and create a view on the table with the original name of the table that exposes the columns in the order your code expects until you can fix that buggy code.
这篇关于如何使用表中的现有行修改 Oracle 中的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用表中的现有行修改 Oracle 中的数据类型
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
