Home » SQL & PL/SQL » SQL & PL/SQL » sequence
sequence [message #294881] Sun, 20 January 2008 07:49 Go to next message
aparna_ora
Messages: 14
Registered: September 2005
Junior Member
hi
I want to create a sequence which is like
-4 -2 0 2 4...
( asked by one interviewer)
how can i create that?
if i used start with -4 and increment by -2 its giving error.

please help me
Re: sequence [message #294883 is a reply to message #294881] Sun, 20 January 2008 07:51 Go to previous messageGo to next message
pablolee
Messages: 2835
Registered: May 2007
Location: Scotland
Senior Member
Increment by 2 not -2
Re: sequence [message #294888 is a reply to message #294883] Sun, 20 January 2008 07:56 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Increment by 2, as pablolee said.
Quote:
(-4) + 2 = -2
(-2) + 2 = 0
By
Vamsi
Re: sequence [message #294890 is a reply to message #294888] Sun, 20 January 2008 07:58 Go to previous messageGo to next message
pablolee
Messages: 2835
Registered: May 2007
Location: Scotland
Senior Member
vamsi, what is the point of your post? It adds nothing to the solution.
Re: sequence [message #294891 is a reply to message #294890] Sun, 20 January 2008 08:03 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Nothing.....
I thought aparna_ora doesn't know calculations on negative numbers. Cool

By
Vamsi
PS: No offense meant. Just kidding.

[Updated on: Sun, 20 January 2008 08:10]

Report message to a moderator

Re: sequence [message #294989 is a reply to message #294891] Mon, 21 January 2008 02:01 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Got a PM from aparna_ora
Quote:
oh... that i know...if u are clever then please help me...
I wrote sequence as
create sequence my_seq
start with -4
increment by -2
nomaxvalue
nominvalue
;
its next value -6 -8 ...
when i used increment by 2
it gives error values not more than nomaxvalue.

i tried all possibilites as per my knowledge...
i want series -4 -2 0 2 4 6 8 ....

can u please help me?
Have a look at this.
If you give nominvalue, it treats as 1.
Try this
create sequence my_seq
start with -4
increment by -2
nomaxvalue
minvalue -4;

Aparna,
I said no offense meant. Please don't take it personal.

By
Vamsi
Re: sequence [message #294994 is a reply to message #294989] Mon, 21 January 2008 02:08 Go to previous messageGo to next message
Michel Cadot
Messages: 64140
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Try this
create sequence my_seq
start with -4
increment by -2
nomaxvalue
minvalue -4;


If you try this you will not go very far:
SQL> create sequence my_seq
  2  start with -4
  3  increment by -2
  4  nomaxvalue
  5  minvalue -4;

Sequence created.

SQL> select my_seq.nextval from dual;
   NEXTVAL
----------
        -4

1 row selected.

SQL> /
select my_seq.nextval from dual
                           *
ERROR at line 1:
ORA-08004: sequence MY_SEQ.NEXTVAL goes below MINVALUE and cannot be instantiated

Quote:
I thought aparna_ora doesn't know calculations on negative numbers.

It seems you neither know it.
Better:
SQL> create sequence my_seq
  2  start with -4
  3  increment by 2
  4  minvalue -4;

Sequence created.

SQL> select my_seq.nextval from dual;
   NEXTVAL
----------
        -4

1 row selected.

SQL> /
   NEXTVAL
----------
        -2

1 row selected.

SQL> /
   NEXTVAL
----------
         0

1 row selected.

SQL> /
   NEXTVAL
----------
         2

1 row selected.

Regards
Michel



Re: sequence [message #295013 is a reply to message #294994] Mon, 21 January 2008 02:43 Go to previous message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
create sequence my_seq
start with -4
increment by -2
nomaxvalue
minvalue -4;
I was intend to post increment by 2 Sad
That was a typo.

By
Vamsi
Previous Topic: Compare Data
Next Topic: problem in metadata.get_ddl
Goto Forum:
  


Current Time: Fri Dec 09 07:33:43 CST 2016

Total time taken to generate the page: 0.08662 seconds