473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to use sequence in FUNCTION?

Hi.

Please help me. I need to port one stored function from Oracle to DB2.
In Oracle there is a sequence used, like this:

SELECT seqTF.nextval INTO seq_nextval FROM dual;

I have lost 2 hours trying to find how to do the same thing in DB2. :-
( Unfortuinately without success.

I tried following variants:

VALUES NEXT VALUE FOR seqTF INTO seq_nextval;
seq_nextval := NEXT VALUE FOR seqTF;
seq_nextval := (SELECT NEXT VALUE FOR seqTF FROM SYSIBM.SYSDUMMY1);

Unfortuinately all variants listed above do not work.

Could you please help me with it?

I need it for DB2 8.2.7.
Function should be as fast as possible, not use any additional tables.

Regards,
Dmitry.

PS. Here is the full code of function I converted from Oracle:

CREATE FUNCTION GetSysTimeFraction() RETURNS timestamp
LANGUAGE SQL
NOT DETERMINISTIC
BEGIN ATOMIC
DECLARE time_str VARCHAR(50);
DECLARE fraction_str VARCHAR(50);
DECLARE seq_nextval INTEGER;
DECLARE tTmStmp TIMESTAMP;

seq_nextval := NEXT VALUE FOR seqTF;

tTmStmp := current timestamp;
time_str := cast(tTmStmp as char(26));
fraction_str := '000000' || cast(cast(substr(time_str, 21, 3) as int)
* 100 + seq_nextval as char(9));
fraction_str := substr(fraction_str, length(fraction_str) - 6, 6);
time_str := substr(time_str, 1, 20);
RETURN cast((time_str || fraction_str) as timestamp);
END@
Apr 4 '08 #1
0 1183

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: ...
7
by: akarl | last post by:
Hi all, Why do I get a warning from gcc with the following program? $ cat test.c #include <stdio.h> int f(int n) { return n;
2
by: dan | last post by:
I have 2 tables, tab1 ( integer incremented sequence , col2, col3 ) and tab2 ( integer from tab1, col4, col5 ). When I call this function to add a record to each table: LOOP select...
15
by: Robby Russell | last post by:
I am trying to track down a method of determining what a sequence name is for a SERIAL is in postgresql. For example, CREATE TABLE foo (id SERIAL PRIMARY KEY NOT NULL, bar TEXT); \d foo...
9
by: John Smith | last post by:
I've been playing with splint, which returns the following warning for the code below: statlib.c: (in function log_norm_pdf) statlib.c(1054,31): Expression has undefined behavior (left operand...
14
by: pat270881 | last post by:
hello, I have to implement a sequence class, however the header file is predefined class sequence { public: // TYPEDEFS and MEMBER CONSTANTS
6
by: Defcon2030 | last post by:
<bHey, can someone help me with this? I've been working on it for a few days now, and my head's starting to spin... </b> // FILE:ex1_imp.cxx // // // // CLASS IMPLEMENTED: sequence (see ex1.h...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
3
by: joe | last post by:
Consider the following program: include <iostream> class Bar { public: int getData9() { m_data = 9; return m_data;} int getData11() { m_data = 11; return m_data;} int m_data;
5
by: =?ISO-8859-1?Q?Marcel_M=FCller?= | last post by:
Hi, I have a question about the execution sequence of the postfix increment operator with respect to a function call. void foo(int type, int*& data); int* sequence;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.