Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5939703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:51:55+00:00 2026-05-22T15:51:55+00:00

How to create a function in DB2 that obtains a value from a sequence

  • 0

How to create a function in DB2 that obtains a value from a sequence and returns it?

It should be possible to use that function in select or insert statement, e.g:

select my_func() from xxx
insert into xxx values(my_func())

Basically I am using the sequence value in a complex formula, and I’d like to encapsulate the calculation inside a function.

Edit: I am not asking how to simply get next value from sequence.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:51:56+00:00Added an answer on May 22, 2026 at 3:51 pm
    CREATE FUNCTION "MYSCHEMA"."MY_FUNC"(PARAM1 VARCHAR(4000))
         RETURNS INT
    SPECIFIC SQL110520140321900 BEGIN ATOMIC
         DECLARE VAR1 INT;
         DECLARE VAR2 INT;
         SET VAR1  = NEXTVAL FOR MY_SEQ;
         SET VAR2 = VAR1 + 2000; --or whatever magic you want to do
         RETURN VAR2;
    END
    

    To try it out:

    SELECT MY_FUNC('aa') FROM SYSIBM.SYSDUMMY1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

why error? CREATE FUNCTION [dbo].[seth] (@IdUrl BIGINT) RETURNS TABLE AS RETURN(SELECT * FROM dbo.NetGraph
Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
CREATE FUNCTION dbo.GetCustomers ( @ZIPCode VARCHAR(255) ) RETURNS TABLE AS BEGIN SELECT * dbo.GetCustomers
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
How come the following doesn't work? CREATE FUNCTION Test (@top integer) RETURNS TABLE AS
I want to create a function that performs a function passed by parameter on
Is there a way to create a function/sub signature that accepts an arbitrary typed
I'm trying to create function that will do this same thing for 3 different
I got this function from someone on here: create FUNCTION [dbo].[fnSplitString] (@s varchar(512),@sep char(1))
Say I have a function f(a, b, c) . Is it possible to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.