Home » SQL & PL/SQL » SQL & PL/SQL » sequence problem
sequence problem [message #206007] Tue, 28 November 2006 06:07 Go to next message
orafacjublu
Messages: 95
Registered: May 2006
Location: KOLKATA
Member
A user selects from a sequence and gets back two values, his select is:

SELECT pk_seq.nextval FROM dual; What is the problem?
Re: sequence problem [message #206012 is a reply to message #206007] Tue, 28 November 2006 06:12 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
First problem: you typed [notag][b] around your text.

You probably have more than 1 row in dual.

[Edit: On second thought, what makes you think you get 2 values back? Is there a gap between calls, or do you actually see more than 1 value being returned?]

[Updated on: Tue, 28 November 2006 06:13]

Report message to a moderator

Re: sequence problem [message #206014 is a reply to message #206007] Tue, 28 November 2006 06:13 Go to previous messageGo to next message
Littlefoot
Messages: 20900
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I don't see any other way, but to do it through an SQL script which looks like this:
SELECT seq_name.nextval FROM dual;
/
where slash (/) sign re-executes previous statement.
Re: sequence problem [message #206015 is a reply to message #206014] Tue, 28 November 2006 06:14 Go to previous messageGo to next message
Littlefoot
Messages: 20900
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Uh-oh, two rows in DUAL ... if I remember well, there's an article on Ask Tom about it, and Tom Kyte wasn't very happy about such things.
Re: sequence problem [message #206018 is a reply to message #206007] Tue, 28 November 2006 06:21 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
What do they get if they do
SELECT * FROM dual;
Re: sequence problem [message #206019 is a reply to message #206014] Tue, 28 November 2006 06:22 Go to previous messageGo to next message
orafacjublu
Messages: 95
Registered: May 2006
Location: KOLKATA
Member
Well I was asked by an interviewer and I was totally dumbfounded.
I hope you might give me some suitable answer for this type of question.
Re: sequence problem [message #206024 is a reply to message #206019] Tue, 28 November 2006 06:32 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
And? What did the interviewer answer when you said "Sorry sir, I don't know, but please tell me!"?
Re: sequence problem [message #206026 is a reply to message #206024] Tue, 28 November 2006 06:34 Go to previous messageGo to next message
orafacjublu
Messages: 95
Registered: May 2006
Location: KOLKATA
Member
He jumped off to another question. But I am still searching for an appropriated answer for it.
Re: sequence problem [message #206027 is a reply to message #206026] Tue, 28 November 2006 06:37 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
orafacjublu wrote on Tue, 28 November 2006 13:34
He jumped off to another question. But I am still searching for an appropriated answer for it.

Hm, he must have been very rude then, otherwise I'd find that quite hard to believe..

But I think you have your answers now, there are at least three possible answers/counter-questions given
Re: sequence problem [message #206031 is a reply to message #206027] Tue, 28 November 2006 06:43 Go to previous messageGo to next message
orafacjublu
Messages: 95
Registered: May 2006
Location: KOLKATA
Member
What will be the answer if I actually see more than 1 value being returned ? I would like an appropriate answer
Re: sequence problem [message #206032 is a reply to message #206012] Tue, 28 November 2006 06:48 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Frank wrote on Tue, 28 November 2006 13:12
You probably have more than 1 row in dual.


What's not appropriate about that answer?
Except for the fact that _if_ it is true, the database is a mess and someone at the DBA's side has been sleeping..
Re: sequence problem [message #206038 is a reply to message #206032] Tue, 28 November 2006 07:07 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
I'd say the most likely answers are (in decreasing order of frequency):

1) They didn't get that - they're just confused.
2) They put ; and a / on a piece of SQL and ran it in SQL*Plus
3) Someone has added an extra line to dual, or has created a local table called dual, or a synonym called dual pointing to another table.

With 1) being by far the most common.
Re: sequence problem [message #206042 is a reply to message #206026] Tue, 28 November 2006 07:17 Go to previous messageGo to next message
vshari
Messages: 9
Registered: October 2005
Location: India/UK
Junior Member
JRowBottom is right here.

There may be a local table or maybe it is pointing to another table
and that what the interviewer may have expected as an answer.

Re: sequence problem [message #206043 is a reply to message #206038] Tue, 28 November 2006 07:17 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
I agree, if it were a real-live situation.
Given the fact that this was an interview-question, I'd start bottom-up
[Edit: that is, for the kind of interview this seems to have been!]

[Updated on: Tue, 28 November 2006 07:19]

Report message to a moderator

Re: sequence problem [message #206058 is a reply to message #206043] Tue, 28 November 2006 08:17 Go to previous message
ab_trivedi
Messages: 460
Registered: August 2006
Location: Pune, India
Senior Member

i am sorry to say but it shows a type of fake interview ...

Previous Topic: utl_file halts
Next Topic: problems with script
Goto Forum:
  


Current Time: Thu Dec 08 12:11:10 CST 2016

Total time taken to generate the page: 0.26094 seconds