Changing data type in oracle without deleting the data

扶醉桌前 提交于 2019-12-12 16:53:43

问题


Product Version Oracle 10g

I have a table in oracle with some data in it. There is a column which of type Number(10,0). Now i want to change it to Number(10,2) to allow decimals. But to change, oracle is not allowing without deleting the existing data. I know i can take the data backup -> delete data -> change type -> insert data back. But the problem is there is an auto insert column which gets value from a sequence. So when i insert it back those id will change....I am not sure that if anyone is using that id as a key to get the data. So how can i change it without altering the ids..

Please help..


回答1:


Probably you want number(12,2) to keep precision. For example, number(7,2) is a number that has 5 digits before the decimal and 2 digits after the decimal.

Alternately, you may disable the trigger / do the work / enable the trigger.




回答2:


  1. Add the new NUMBER(12,2) column, but with a different name.
  2. Update the new column, converting all the values from the old column.
  3. Drop the old column.
  4. Rename the new column with the desired name.


来源:https://stackoverflow.com/questions/12173214/changing-data-type-in-oracle-without-deleting-the-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!