CengSin / oracle

GORM oracle driver
Other
112 stars 43 forks source link

查询一条数据到结构体报错 #14

Open xiaotang0128 opened 3 years ago

xiaotang0128 commented 3 years ago

err = db.Where("ID=?",1).First(&info).Error 报错,dpiStmt_execute:ORA-00933:SQL command not properly ended

austin-millan commented 3 years ago

Oracle 11 doesn't seem to support "FETCH" clause (introduced in Oracle 12). From the README:

Required dependency Install Oracle 12C+

The First clause produces the query here:

        if limit := limit.Limit; limit > 0 {
            builder.WriteString(" FETCH NEXT ")
            builder.WriteString(strconv.Itoa(limit))
            builder.WriteString(" ROWS ONLY")
        }

Which leads to the error:

SELECT * FROM TABLE WHERE ID = '1' ORDER BY TABLE.ID  FETCH NEXT 1 ROWS ONLY;
                                                      *
ERROR at line 1:
ORA-00933: SQL command not properly ended

Edit: This means you should avoid using First and Limit clauses in this library for versions < Oracle 12g.