PHP/Oracle,从 Merge Into 返回插入的 id
我目前正在开发一个使用 Oracle 数据库的 PHP 项目。为了更新表,我正在使用的 php 代码使用 SQL“MERGE INTO”方法循环遍历表并查看另一个表中是否存在多个记录的值。如果它们尚不存在,则这些值将插入到我的表中。如果值已经存在,则不会发生任何事情。
我想在此之后运行另一个查询,该查询使用在 MERGE INTO 查询中创建的自动递增 id。有没有办法获取新创建的 id 数组?我希望有类似 mysql_insert_id 的东西,但我还没有找到类似的东西。
谢谢!
I am currently working on a PHP project with an Oracle database. To update a table, the php code I'm working with uses a SQL "MERGE INTO" method to loop through a table and see if values for multiple records exist in another table. If they don't exist yet, the values are inserted into my table. If the values already exist, nothing happens.
I would like to have another query run after this that uses the auto incremented id's created in the MERGE INTO query. Is there a way to get an array of the newly created ids? I was hoping for something like mysql_insert_id, but I haven't found anything like that yet.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Oracle 自 9i 起就支持 MERGE 语法。还没有尝试过,但您也许可以在 MERGE 语句上使用 RETURNING 子句...
Oracle 使用序列来处理自动递增的值。创建序列后,您可以使用:
.. 获取当前值,如
mysql_insert_id
将返回的值。要填充主键,您可以使用:要在 INSERT 语句中填充主键,您可以使用:
您可以使用触发器作为替代方法,但它们不会返回当前值。
Oracle has supported the MERGE syntax since 9i. Haven't tried, but you might be able to use the RETURNING clause on the MERGE statement...
Oracle uses sequences for handling automatically incremented values. Once you've created a sequence, you can use:
..to get the current value, like what
mysql_insert_id
would return. To populate a primary key, you'd use:To populate a primary in an INSERT statement, you'd use:
You can use triggers as an alternative, but they won't return the current value.
什么是自动递增 id? AFAIK,Oracle 中没有这样的东西。您可以通过在表上添加触发器和序列号来模拟该行为,但肯定没有 mysql_insert_id() 的等效项。
我认为你需要回去寻找另一种方法来识别你的记录。
C.
What auto_incremented ids? AFAIK, There is no such thing in Oracle. You can simulate the behaviour by adding a trigger on the table and a sequence number but there is certainly no equivalent of mysql_insert_id().
I think you need to go back and find another way to identify your records.
C.