random fetch using cursor



IBM's flagship relational database management system

random fetch using cursor

Postby aruljyothii » Fri Apr 01, 2011 8:08 pm

i want to select a row randomly from my table using primary key..... can any one help me in this with with query..... pls...
aruljyothii
 
Posts: 2
Joined: Fri Apr 01, 2011 7:43 pm
Has thanked: 0 time
Been thanked: 0 time

Re: random fetch using cursor

 

Re: random fetch using cursor

Postby enrico-sorichetti » Fri Apr 01, 2011 8:18 pm

no until You explain better the requirement

review the SELECT WHERE syntax to realize that what You ask for is quite awkward!
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: random fetch using cursor

Postby aruljyothii » Mon Apr 04, 2011 7:17 pm

my table looks like as follows.
creat table qbank
( qno numeric(2),
mid char(5),
qtext varvhar(160),
ch1 varchar(30),
ch2 varchar(30),
ch3 varchar(30),
ch4 varchar(30),
tqlevel char(1)
)
where qno = question number,
mid = module id,
qtext = question,
ch1 = choice 1,
ch2 = choice 2,
ch3 = choice 3,
ch4 = choice 4,
tqlevel = question mark
From this table i want to fetch random questions from a particular module. not in sequence. using cursors.... can anyone help me in this with a example query...
aruljyothii
 
Posts: 2
Joined: Fri Apr 01, 2011 7:43 pm
Has thanked: 0 time
Been thanked: 0 time

Re: random fetch using cursor

Postby Akatsukami » Mon Apr 04, 2011 7:37 pm

Is qno unique over all, or only within mid? What language do you intend to embed your SQL in?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: random fetch using cursor

Postby GuyC » Tue Apr 05, 2011 4:53 pm

declare c1 cursor for select rand() as sequence , qno, qtext  from qbank where mid = ?  order by 1
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post