关于代码片段的说明
我在一个通过 C 访问 Informix 的遗留应用程序中看到以下代码片段。任何人都可以解释代码中的 SQL 试图实现什么目的吗?谢谢。
EXEC SQL BEGIN DECLARE SECTION;
int i_tableref;
EXEC SQL END DECLARE SECTION;
/* Some code here */
if (!i_sel_ref)
{
exec sql begin declare section;
const char *sql1 =
"select refer_num.nextval from table ( SET{''} )";
exec sql end declare section;
exec sql prepare oref_sel_fid from :sql1;
if ( sqlca.sqlcode != SQL_OK )
{
/* some code */
}
/* More code */
}
I see the following code fragment in a legacy application that accesses Informix through C. Can anyone explain what the SQL in the code is trying to achieve? Thanks.
EXEC SQL BEGIN DECLARE SECTION;
int i_tableref;
EXEC SQL END DECLARE SECTION;
/* Some code here */
if (!i_sel_ref)
{
exec sql begin declare section;
const char *sql1 =
"select refer_num.nextval from table ( SET{''} )";
exec sql end declare section;
exec sql prepare oref_sel_fid from :sql1;
if ( sqlca.sqlcode != SQL_OK )
{
/* some code */
}
/* More code */
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信它正在从名为refer_num 的数据库序列中获取下一个值。序列是一种为数字唯一标识符生成值的方法 - 有点像某些 DBMS 中的 IDENTITY 列。我不了解 Informix,但我的猜测是“table ( SET{''} )”是一种生成具有 1 行的伪表的方法,以便您可以执行实际上不需要访问的 select 语句任何真实的数据库表。 Oracle 有一个名为 DUAL 的特殊表用于此目的,这在 Oracle 中很常见:
I believe it is obtaining the next value from a database sequence called refer_num. Sequences are a way of generating values for numeric unique identifiers - a bit like IDENTITY columns in some DBMSs. I don't know Informix, but my guess is that "table ( SET{''} )" is a way of generating a pseudo-table with 1 row so that you can perform a select statement that doesn't actually need to access any real database table. Oracle has a special table called DUAL for this purpose, and this would be a common sight in Oracle:
要在 Informix 中获取序列生成器的下一个值:
select
your_seq_generator_name.nextval
fromtable(set{1});
for getting next value of a sequence generator in Informix:
select
your_seq_generator_name.nextval
fromtable(set{1});