简体   繁体   English

获取最后插入的行的ID ORACLE / PHP

[英]Get the id of the last inserted row ORACLE/PHP

How to get the last id using php 如何使用php获取最后的ID

similar mysqli_insert_id($conexao) 类似的mysqli_insert_id($conexao)

Many Oracle programs use database objects called SEQUENCE s to generate unique IDs. 许多Oracle程序使用称为SEQUENCE的数据库对象来生成唯一的ID。 If you know which sequence is used for the id in the table you just INSERT ed into, simply say 如果您知道要INSERT表的ID使用哪个序列,只需说

SELECT sequencename.CURRVAL FROM DUAL;

immediately after the insert, in the same database connection, and you'll get the id number. 在插入后立即在同一数据库连接中,您将获得ID号。

SELECT MAX(id) and similar constructs work fine as long as you only, ever, have one connection to the database: meaning they don't work. SELECT MAX(id)和类似的结构只要您与数据库只有一个连接就可以正常工作:这意味着它们不起作用。 Basically they're not thread-safe. 基本上,它们不是线程安全的。 They're also more expensive than CURRVAL . 它们也比CURRVAL贵。

Assuming that your ids are auto-incremented in ascending order you could query for the highest id... 假设您的ID以升序自动递增,则可以查询最高ID ...

SELECT id from table ORDER BY id DESC LIMIT 1

that should give you the highest id and if your ids are auto-incremented this should be the last entry... 这应该为您提供最高的ID,如果您的ID是自动递增的,那么这应该是最后一个条目...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM