473,387 Members | 1,721 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.

Create sequence <seq_name>

Sql>create sequence s1 increment by 1 start with 1;
sql>select s1.nextval from dual;
ans:
Nextval
--------
1
but,how to get below output
nextval
---------
2
3
4
5
6
7
8
9
10
11
12
13
14
15
14 rows
Oct 29 '10 #1
1 2628
amitpatel66
2,367 Expert 2GB
You can do something like this:

Expand|Select|Wrap|Line Numbers
  1. SQL> create sequence my_test_seq
  2.   2  start with 1
  3.   3  increment by 1
  4.   4  order
  5.   5  nocache
  6.   6  nocycle;
  7.  
  8. Sequence created.
  9.  
  10. SQL> create or replace type my_Tab_num IS TABLE OF NUMBER;
  11.   2  /
  12.  
  13. Type created.
  14.  
  15.  
  16. SQL> create or replace function my_Test_func (get_num IN NUMBER) RETURN my_tab_num AS
  17.   2  mytab my_Tab_num := my_tab_num();
  18.   3  BEGIN
  19.   4  FOR I IN 1..get_num LOOP
  20.   5  mytab.extend;
  21.   6  select my_test_seq.nextval
  22.   7         INTO mytab(I)
  23.   8  FROM dual;
  24.   9  END LOOP;
  25.  10  RETURN mytab;
  26.  11  END;
  27.  12  /
  28.  
  29. Function created.
  30.  
  31. SQL> select my_test_Seq.nextval from dual;
  32.  
  33.    NEXTVAL
  34. ----------
  35.         56
  36.  
  37. SQL> SELECT * FROM TABLE(my_Test_func(3));
  38.  
  39. COLUMN_VALUE
  40. ------------
  41.           57
  42.           58
  43.           59
  44.  
  45. SQL> SELECT * FROM TABLE(my_Test_func(15));
  46.  
  47. COLUMN_VALUE
  48. ------------
  49.           60
  50.           61
  51.           62
  52.           63
  53.           64
  54.           65
  55.           66
  56.           67
  57.           68
  58.           69
  59.           70
  60.           71
  61.           72
  62.           73
  63.           74
  64.  
  65. 15 rows selected.
  66.  
  67. SQL> select my_test_seq.nextval from dual;
  68.  
  69.    NEXTVAL
  70. ----------
  71.         75
  72.  
  73. SQL>  SELECT * FROM TABLE(my_Test_func(2));
  74.  
  75. COLUMN_VALUE
  76. ------------
  77.           76
  78.           77
  79.  
  80. SQL> 
  81.  
  82.  
Oct 30 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve Morrell | last post by:
Hi there, I'm trying to write a piece of sql to set an Oracle sequence's nextval to a number specified my the max value in a set of columns. The sequence is populating these columns, so I want...
1
by: JohnLH | last post by:
Hi, I am trying to get the meta data of a sequence that I created out from the system catalogs, so that I can reconstruct the SQL Statement. I need this for pre and post PG 7.3 ... or either. I...
2
by: Ken | last post by:
I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access could not create the sequence number as soon as the value has...
2
by: Lee Harr | last post by:
I must have a fundamental misunderstanding about using schema. Before using schema, I usually have a file that has my database definition, and I can play that file back in to a new database to...
1
by: Grant | last post by:
I'm trying to set up the Interchange 5.2 shopping cart (icdevgroup.org) to use the CREATE SEQUENCE functionality of pgsql properly and I'm having some trouble. The table is called order_items and...
1
by: Marek Lewczuk | last post by:
Hello, I would like to ask if my problem with sequence is a proper behavior or this is a bug (probably not)... I have a table: CREATE TABLE "testtable" ( "serialfield" SERIAL,...
7
by: urban.widmark | last post by:
Hello We are having some problems with triggers, sequences and union all in V8 on code that worked fine in V7. Was wondering if someone else has seen this and/or knows what to do. A trigger...
1
by: simun.selak | last post by:
On my local installation of DB2 on AS/400 (BTW., how do I find out which version od DB2 I have?) I have created these SQL statements: CREATE SEQUENCE a.seq AS INTEGER START WITH 8955 INCREMENT...
4
by: kudinesh | last post by:
how to create a sequence menttioned below..for number generators. CREATE SEQUENCE sequ START WITH 1 INCREMENT BY 1
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.