Oracle使用OCCI和C++获取最后插入的行id
Oracle get last inserted row id using OCCI and C++
给定上面的代码,我如何获取插入数据库的行的ID。我正在使用C++和oracle OCCI接口:
std::stringstream sqlStream("");
sqlStream << "INSERT INTO MYTABLE (COL1, COL2, COL3) VALUES (1, 2, 3) RETURNING ID INTO :my_id_param";
std::string sql(sqlStream.str());
std::cout << sql << std::endl;
std::unique_ptr<oracle::occi::Statement> stmt(connection->createStatement());
stmt->execute(sql.c_str());
//??? How can I access here the my_id_param ?
谢谢你的帮助。
您可以使用匿名PL/SQL并注册OUT参数来捕获生成的ID。这直接适用于序列,我还没有尝试过在触发器中使用序列。
std::stringstream sqlStream("");
sqlStream << "BEGIN INSERT INTO MYTABLE (COL1, COL2, COL3) VALUES (1, 2, 3) RETURNING ID INTO :1; END;";
std::string sql(sqlStream.str());
std::cout << sql << std::endl;
std::unique_ptr<oracle::occi::Statement> stmt(connection->createStatement(sql.c_str()));
stmt->registerOutParam(1, oracle::occi::OCCIINT);
stmt->executeUpdate();
int id = stmt->get(1);
// Use id...
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 预处理器:插入结构名称中的前一个行号
- 在未初始化映射的情况下,将值插入到映射的映射中
- 如何在c++中只将键插入到bimap的一侧
- 如何将结构插入到集合中并打印集合的成员
- C++json插入数组
- Visual Studio 2019:插入多个C++风格的单行注释
- nlohmann-json将一个数组插入到另一个数组中
- 有效地使用std::unordered_map来插入或增加键的值
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- 正在插入动态数组
- 插入或删除时获取usb的dos_name
- 从函数角度看ID到文件路径的内部与外部映射
- 如何使用 QSqlQuery 和 SQLite 从新插入的行中获取 ID
- Oracle使用OCCI和C++获取最后插入的行id
- 如何在另一个表中使用表的上次插入id
- 如何获取插入菜单项时要使用的下一个命令 ID
- C++MySql获取最后插入的id
- DBExpress和mysql最后插入id