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 ?
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.