本文介绍了在同一个select语句中递增序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是当在同一个

select语句中多次使用AddID时,它会在所有位置返回相同的值。我怎么能用
强制函数AddID来增加OBJECTID序列?


这是一个基本的使用示例:

SELECT AddID( ),来自table1的AddID(),AddID(),column1

这是AddID的样子:


CREATE FUNCTION Admin.AddID()

返回INTEGER

F1:开始原子

DECLARE I INTEGER;

SET I =(对象的下一个值);

返回I;

结束

The problem is that when AddID is used multiple times in the same
select statement, it returns the same value in all places. How could I
force function AddID to increment OBJECTID sequence?

Here is a basic sample of usage:
SELECT AddID(), AddID(), AddID(), column1 from table1
Here is how AddID looks like:

CREATE FUNCTION Admin.AddID()
RETURNS INTEGER
F1: BEGIN ATOMIC
DECLARE I INTEGER;
SET I = (NEXT VALUE FOR OBJECTID);
RETURN I;
END

推荐答案






我已在其他新闻组你可以使用外部

功能。以下是我刚才编写的代码来验证这一点:


-------------------------- -------------------------------------

import java.sql。 *;


公共类测试扩展COM.ibm.db2.app.UDF {

public void getNextSequenceId(int value)抛出异常{

连接con = getConnection();

语句stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(" VALUES NEXT VALUE FOR seq" ;);

while(rs.next()){

value = rs.getInt(1);

}

rs.close();

stmt.close();

set(1,value);

}

}

----------------------------------- ----------------------------

CREATE SEQUENCE seq @


CREATE FUNCTION getNextSeqValue()

RETURNS INTEGER

EXTERNAL NAME''Test.getNextSequenceId''

LANGUAGE JAVA

PARAMETER STYLE DB2GENERAL

NOT DETERMINISTIC

无外接行动

读取SQL数据

允许并行@

------------- --------------------------------------------------



I already said in the other news group that you could use an external
function. And here is the code I just wrote to verify this:

---------------------------------------------------------------
import java.sql.*;

public class Test extends COM.ibm.db2.app.UDF {
public void getNextSequenceId(int value) throws Exception {
Connection con = getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("VALUES NEXT VALUE FOR seq");
while (rs.next()) {
value = rs.getInt(1);
}
rs.close();
stmt.close();
set(1, value);
}
}
---------------------------------------------------------------
CREATE SEQUENCE seq@

CREATE FUNCTION getNextSeqValue()
RETURNS INTEGER
EXTERNAL NAME ''Test.getNextSequenceId''
LANGUAGE JAVA
PARAMETER STYLE DB2GENERAL
NOT DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
ALLOW PARALLEL@
---------------------------------------------------------------


这篇关于在同一个select语句中递增序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 15:26