Informix:如何获取最后插入的记录的标识 [英] Informix: how to get an id of the last inserted record

查看:51
本文介绍了Informix:如何获取最后插入的记录的标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在INSERT语句之后获取SERIAL列的值的最有效方法是什么? IE.我正在寻找一种复制MS SQL @@IDENTITYSCOPE_IDENTITY功能的方法

What's the most efficient way of getting the value of the SERIAL column after the INSERT statement? I.e. I am looking for a way to replicate @@IDENTITY or SCOPE_IDENTITY functionality of MS SQL

推荐答案

最后一个SERIAL插入的值存储在SQLCA记录中,作为sqlerrd数组中的第二个条目. Brian的答案对于ESQL/C是正确的,但是您没有提到您使用的是哪种语言.

The value of the last SERIAL insert is stored in the SQLCA record, as the second entry in the sqlerrd array. Brian's answer is correct for ESQL/C, but you haven't mentioned what language you're using.

如果您正在编写存储过程,则可以这样找到该值:

If you're writing a stored procedure, the value can be found thus:

LET new_id = DBINFO('sqlca.sqlerrd1');

如果使用DBI,也可以在$sth->{ix_sqlerrd}[1]中找到

It can also be found in $sth->{ix_sqlerrd}[1] if using DBI

还有其他语言/界面的变体,但我相信您会明白的.

There are variants for other languages/interfaces, but I'm sure you'll get the idea.

这篇关于Informix:如何获取最后插入的记录的标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆