If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How are you using the SEQUENCE object ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-16-09, 17:17
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question How are you using the SEQUENCE object ?

How are you using the SEQUENCE object in your daily practice ?

It's interesting to me.

Give me some ideas, different from identify field.

Thanks, Lenny
Reply With Quote
  #2 (permalink)  
Old 11-17-09, 17:01
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Query is working good...

This query is working good:

Code:
drop SEQUENCE SEQ1;

CREATE SEQUENCE SEQ1
       START WITH 1
       INCREMENT BY 1

With TestTbl (seq#, str) as 
(
select 1, '000002050'
  from sysibm.sysdummy1
union all
select 2, '760000090'
  from sysibm.sysdummy1
union all
select 3, '005000001'
  from sysibm.sysdummy1
union all 
select 4, '090005000'
  from sysibm.sysdummy1
union all
select 5, '070000400'
  from sysibm.sysdummy1
union all
select 6, '000100080'
  from sysibm.sysdummy1
union all
select 7, '800000900'
  from sysibm.sysdummy1
union all
select 8, '230050060'
  from sysibm.sysdummy1
union all
select 9, '040601000'
  from sysibm.sysdummy1
) 
select NEXT VALUE FOR SEQ1 nextseq, seq#, str
From TestTbl
Lenny
Reply With Quote
  #3 (permalink)  
Old 11-17-09, 17:09
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Thumbs down But this query is not good (SQLCODE = -348)

This query doesn't work:

Code:
With TestTbl (seq#, str) as 
(
select 1, '000002050'
  from sysibm.sysdummy1
union all
select 2, '760000090'
  from sysibm.sysdummy1
union all
select 3, '005000001'
  from sysibm.sysdummy1
union all 
select 4, '090005000'
  from sysibm.sysdummy1
union all
select 5, '070000400'
  from sysibm.sysdummy1
union all
select 6, '000100080'
  from sysibm.sysdummy1
union all
select 7, '800000900'
  from sysibm.sysdummy1
union all
select 8, '230050060'
  from sysibm.sysdummy1
union all
select 9, '040601000'
  from sysibm.sysdummy1
) 
select t1.nextseq, t1.seq#, t1.str 
from 
(select NEXT VALUE FOR SEQ1 nextseq, seq#, str
  From TestTbl ) t1
Quote:
SQL0348N "NEXT VALUE FOR SEQ1" cannot be specified in this context. SQLSTATE=428F9

State:428F9,Native:-348,Origin:[IBM][CLI Driver][DB2]
Lenny
Reply With Quote
  #4 (permalink)  
Old 11-17-09, 18:22
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Lenny77 View Post
How are you using the SEQUENCE object in your daily practice ?

It's interesting to me.

Give me some ideas, different from identify field.

Thanks, Lenny
It's not very different from an identity column. When you create an identity column that is generated by default/always, then DB2 creates a sequence to manage it.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 11-18-09, 10:27
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Red face Not clear

Quote:
Originally Posted by Marcus_A View Post
It's not very different from an identity column. When you create an identity column that is generated by default/always, then DB2 creates a sequence to manage it.
Thank you, Marcus !

It was the first that I have thought up....

But not all so is simple even this way of application....

Look the previous message.

Lenny
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On