sql - 在 SQL Developer 中更改数据库中的表引发错误
问题描述
我有以下查询来更改我的客户表以添加一列以检查客户是否处于活动状态。
ALTER TABLE COMPANY.CUSTOMER
ADD (isActive VARCHAR2(18 CHAR) DEFAULT 'FALSE' NOT NULL)
CHECK(isActive in ('TRUE','FALSE'));
我收到以下错误:
RA-01735:无效的 ALTER TABLE 选项
01735。00000 -“无效的 ALTER TABLE 选项”
我试图更改顺序,但仍然没有工作。你能帮我解释为什么它不能改变桌子吗?
另外如何确保插入时 TRUE 或 FALSE 是否始终为大写?
解决方案
You can split up the CHECK constraint from the ADD COLUMN for one route...
/* drop table customer_so purge; */
create table customer_so (id integer, name varchar2(50));
ALTER TABLE CUSTOMER_SO
ADD (ISACTIVE VARCHAR2(20) DEFAULT 'FALSE' );
ALTER TABLE CUSTOMER_SO
ADD CONSTRAINT CUSTOMER_SO_CHK1 CHECK
(ISACTIVE IN ('TRUE', 'FALSE'))
ENABLE;
Or, like you had, all in one go -
/* drop table customer_so purge; */
create table customer_so (id integer, name varchar2(50));
ALTER TABLE CUSTOMER_SO
ADD (ISACTIVE VARCHAR2(20) DEFAULT 'FALSE' constraint CUSTOMER_SO_CHK1 CHECK
(ISACTIVE IN ('TRUE', 'FALSE')));
So basically end of the day, you're missing the 'CONSTRAINT' keyword.
Since you tagged oracle-sqldeveloper, you should know the EDIT TABLE ddialog lets you click through these changes, and will generate the DDL for you -
Finally, by default, strings in Oracle are case-sensitive, so your check constraint will work as desired.
推荐阅读
- javascript - NodeJS:承诺没有回应
- c# - ViewDataDictionary 模型类型异常
- windows - 如何检查WMIC是否输出空字符串或请求的Windows原始产品密钥?
- sage - 用矩阵组合集合:sagemath
- spring-webflux - 使用spring响应式webClient面临问题“WebClientRequestException:挂起的获取队列已达到其最大大小1000”
- php - 重定向和 reauth=1 的奇怪 wp-admin 登录问题
- flutter - 使用 Flutter 从一个未来获取价值并在另一个未来使用它
- javascript - 当 JSON.stringify 显示空对象但实际上它不是空的时如何获取实际内容
- javascript - 鼠标悬停时的 Blazor 运动?
- pytorch - 为什么 triton 语言比 pytorch 快?