duanjiu4498 2019-07-15 10:08
浏览 331
已采纳

ORA-01735使用内联约束更改表时

Oracle Version: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Query: ALTER TABLE "TAB" ADD "XVAR" CLOB CHECK ("XVAR" IS JSON);

I can't quite understand what is wrong with this statement. Can someone point out what is wrong with this ?

As far as I understand, the constraint does not need to be named by default. Even naming the constraint has not helped here.

I'm trying to run the query on the DB via the go-oci8 driver.

The code to do the same is:

package main

import (
"database/sql"
"fmt"
_ "github.com/mattn/go-oci8"
)

func main() {
db, err := sql.Open("oci8", "<connectionString>")
if err != nil {
    fmt.Println(err)
    return
}
defer func(db *sql.DB) {
    if err := db.Close(); err != nil{
        fmt.Println(err)
    }
}(db)

_sql := `ALTER TABLE "TAB" ADD "XVAR" CLOB CHECK ("XVAR" IS JSON);`

result, err := db.Exec(_sql)
if err != nil {
    fmt.Println("Issue with altering table...")
    fmt.Println(err)
    return
}

fmt.Println(result.RowsAffected())

}

Output:

Issue with altering table...
ORA-01735: invalid ALTER TABLE option

Is there anything wrong with my query ? Or does it look like an issue with the 3rd party driver I'm using to do the same ?

  • 写回答

1条回答 默认 最新

  • dsfdsf21321 2019-07-15 11:46
    关注

    Remove the semicolon at the end of the ALTER statement:

    _sql := `ALTER TABLE "TAB" ADD "XVAR" CLOB CHECK ("XVAR" IS JSON)`
    

    The semicolon is client statement separator and is not part of the actual statement (for SQL; PL/SQL is a different matter).

    Demo of the problem and fix, via dynamic SQL rather than your stack, but same problem and solution:

    BEGIN
      EXECUTE IMMEDIATE 'ALTER TABLE "TAB" ADD "XVAR" CLOB CHECK ("XVAR" IS JSON);';
    END;
    /
    
    ORA-01735: invalid ALTER TABLE option
    ORA-06512: at line 2
    
    BEGIN
      EXECUTE IMMEDIATE 'ALTER TABLE "TAB" ADD "XVAR" CLOB CHECK ("XVAR" IS JSON)';
    END;
    /
    
    Table altered.
    

    db<>fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。