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 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败