0

I created a new TYPE in Oracle in order to have parity between my table and a local c++ object (I am using OCCI interface for C++).

In the code I use

void insertRowInTable ()
  {

    string sqlStmt = "INSERT INTO MY_TABLE_T VALUES (:x)";

    try{
    stmt = con->createStatement (sqlStmt);
    ObjectDefinition *o = new ObjectDefinition ();

    o->setA(0);
    o->setB(1);
    o->setC(2);
    stmt->setObject (1, o);
    stmt->executeUpdate ();
    cout << "Insert - Success" << endl;
    delete (o);
    }catch(SQLException ex)
    {
       //exception code
    }

The code compiles, connects to db but throws the following exception

Exception thrown for insertRow Error number: 947 ORA-00947: not enough values

Do I have a problematic "sqlStmt"? Is something wrong with the syntax or the binding?

Of course I have already setup an environment and connection

 env = Environment::createEnvironment (Environment::OBJECT);
    occiobjm (env);
    con = env->createConnection (user, passwd, db);
4

1 回答 1

0

表中有多少列?错误消息表明您没有在插入语句中提供足够的值。如果只提供 VALUES 子句,则必须提供表中的所有列。否则,您需要列出您为其提供值的每一列:

string sqlStmt = "INSERT INTO MY_TABLE_T (x_col) VALUES (:x)";

编辑: VALUES 子句列出占位符参数。我认为您需要为每个传递的值列出一个,例如:

string sqlStmt = "INSERT INTO MY_TABLE_T (GAME_ID, VERSION) VALUES (:x1,:x2)"

查看Oracle OCCI 文档中的occidml.cpp以获取示例。

于 2016-10-17T12:36:15.553 回答