如果列为空,您可以更改数据类型:
ALTER TABLE student MODIFY (sfee VARCHAR2(10));
如果您需要保留数据,如您所说,您可以重命名列,添加具有新数据类型的新列,复制数据并删除重命名的旧列:
CREATE TABLE student (sno NUMBER, sname VARCHAR2(10), scourse VARCHAR2(10), sfee NUMBER);
INSERT INTO student VALUES (1, 'RAM', 'SQL', 2100);
INSERT INTO student VALUES (2, 'JAM', 'JAVA', 3000);
ALTER TABLE student RENAME COLUMN sfee TO sfee_old;
ALTER TABLE student ADD (sfee VARCHAR2(10));
UPDATE student SET sfee = TO_CHAR(sfee_old,'fm9999');
ALTER TABLE student DROP COLUMN sfee_old;
如果它是一张大桌子,我建议在物理上重建它:
ALTER TABLE student MOVE;
现在SFEE
可以存储字符串值:
INSERT INTO student VALUES (3, 'TOM', 'LINUX', 'AJAY');
SELECT * FROM student;
如果它是一个巨大的生产表,我建议简单地创建一个新表:
CREATE TABLE student_tmp AS
SELECT sno, sname, scourse, to_char(sfee,'fm9999') as sfee FROM student;
DROP TABLE student;
RENAME student_tmp TO student;
最后一个问题:为什么 SQL 课程比 Java 课程便宜 ;-) ?