json - 向具有 JSON CLOB 约束 Oracle 的表添加列

标签 json oracle clob oracle12c

我正在尝试向 Oracle 表添加一列,并检查我要添加的 CLOB 类型列的 JSON。

ALTER TABLE TAB1 (ADD COL_NEW CLOB CONSTRAINT CONS1 (CLOB IS JSON));
ALTER TABLE TAB1 ADD COL_NEW CLOB CONSTRAINT CONS1 (CLOB IS JSON) ;
ALTER TABLE TAB1 ADD COL_NEW CLOB CONSTRAINT CONS1 (CLOB IS JSON);

以上所有操作都失败并出现错误:

ERROR execute() failed with: ORA-02253: constraint specification not allowed here     
ERROR execute() failed with: ORA-01735: invalid ALTER TABLE option 

最佳答案

语法为constraint <<constraint name>> <<constraint type>> (<<columns>> 。您正在尝试创建检查约束,因此您的约束类型应为 check 。您还需要在 (<<column name>> is json) 中指定新列的名称。表达式,而不是 clob数据类型。所以你想要constraint cons1 check( col_new is json )

ALTER TABLE table_name
  ADD( column_name CLOB 
         CONSTRAINT constraint_name CHECK (column_name IS JSON ));

关于json - 向具有 JSON CLOB 约束 Oracle 的表添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32703167/

相关文章:

C# Linq JSON 嵌套数组的奇怪行为

sql - 使用 PIVOT 函数 (Oracle) 的行到列

oracle - 此行级触发器发生了什么故障?

java - 将字符串转换为 Clob

java - 如何以与实现无关的方式在 JPA 中创建 Clob

java - com.ibm.db2.jcc.am.SqlException : [jcc][10120][11936][4. 14.88] 无效操作 : Lob is closed. ERRORCODE=-4470,SQLSTATE=null

java - 如何在servlet中获取jQuery JSON请求参数?

Android:在 Android 中为应用程序离线存储 JSON 数据的最佳方式是什么?

sql - 如何从 postgres 中的同一张表中获取分层 json

java - 修改 Oracle Sql 查询返回的结果内容