How to get the last row of an Oracle a table

后端 未结 7 2216
名媛妹妹
名媛妹妹 2020-11-28 08:31

I want to get the last row, which I inserted into a table in an Oracle 11g Express database. How can I do this?

7条回答
  •  有刺的猬
    2020-11-28 09:21

    $sql = "INSERT INTO table_name( field1, field2 )  VALUES ('foo','bar') 
            RETURNING ID INTO :mylastid";
    $stmt = oci_parse($db, $sql);
    oci_bind_by_name($stmt, "mylastid", $last_id, 8, SQLT_INT);
    oci_execute($stmt);
    
    echo "last inserted id is:".$last_id;
    

    Tip: you have to use your id column name in {your_id_col_name} below...

    "RETURNING {your_id_col_name} INTO :mylastid"
    

提交回复
热议问题