Home » SQL & PL/SQL » SQL & PL/SQL » sequence
sequence Sun, 20 January 2008 07:49
 aparna_ora Messages: 14Registered: 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
 pablolee Messages: 2844Registered: 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
 vamsi kasina Messages: 2108Registered: October 2003 Location: Hyderabad, India 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
 pablolee Messages: 2844Registered: 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
 vamsi kasina Messages: 2108Registered: October 2003 Location: Hyderabad, India Senior Member
Nothing.....
I thought aparna_ora doesn't know calculations on negative numbers.

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
 vamsi kasina Messages: 2108Registered: October 2003 Location: Hyderabad, India 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
 Michel Cadot Messages: 64945Registered: March 2007 Location: Nanterre, France, http://... Senior MemberAccount 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
 vamsi kasina Messages: 2108Registered: October 2003 Location: Hyderabad, India Senior Member
```create sequence my_seq
start with -4
increment by -2
nomaxvalue
minvalue -4;```
I was intend to post increment by 2
That was a typo.

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

Current Time: Fri Jun 23 02:07:10 CDT 2017

Total time taken to generate the page: 0.25107 seconds