我们char(1)
在 Oracle 中使用列来存储布尔值,其中的值是"1"
or"0"
代表真或假。但是,我想将这些更改为number(1)
列,其中值为1
or 0
。如果表中已经存在值,您似乎无法更改此列的类型。所以我必须做这样的事情:
ALTER TABLE TPM_TRAININGPLANSOLUTIONS DROP CONSTRAINT SYS_C0010178;
ALTER TABLE TPM_TRAININGPLANSOLUTIONS RENAME COLUMN ISMARKERCOMPLETION TO ISMARKER_CHAR;
ALTER TABLE TPM_TRAININGPLANSOLUTIONS ADD (ISMARKERCOMPLETION NUMBER(1) NOT NULL);
UPDATE TPM_TRAININGPLANSOLUTIONS SET ISMARKERCOMPLETION = ISMARKER_CHAR; -- This takes about 10 min
ALTER TABLE TPM_TRAININGPLANSOLUTIONS DROP COLUMN ISMARKER_CHAR; -- Also very slow
ALTER TABLE TPMDBO.TPM_TRAININGPLANSOLUTIONS
ADD ( CONSTRAINT SYS_C0010178
CHECK (ISMARKERCOMPLETION in (0,1))
NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE );
但是,我们的数据库中有几十个这样的列。有没有更快的方法来做到这一点?