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 中的数据类型


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01