Randomly generate numbers in DB2



IBM's flagship relational database management system

Randomly generate numbers in DB2

Postby Valenteno123 » Tue Nov 23, 2010 12:45 pm

I would like to share some info. I am not sure if it has already posted. Am very sorry if it is already
published.

We can get the randomly generated numbers in db2 using a function called "RAND" it can be used as RAND()

This is very usefull when you want the randomization logic in your code. For example if you want the
db2 to return different set of rows(while using cursors) every time you query on table.

Let me know if you dont understand anything.
Valenteno123
 
Posts: 5
Joined: Mon Jul 21, 2008 2:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Randomly generate numbers in DB2

 

Re: Randomly generate numbers in DB2

Postby dick scherrer » Wed Nov 24, 2010 2:57 am

Hello,

If i run the same query multiple times, why might i want inconsistent results (i.e. a different set of rows returned)?

How does using a cursor relate?

Why might i want "randomization logic" in my code?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Randomly generate numbers in DB2

Postby Valenteno123 » Wed Nov 24, 2010 7:42 am

Dick i am sorry . its not different set of results , its same result in the different order.

Randomization , I will give you an example.

You own a company(Insurance provider) , many agents are working in your company and you have a online application where in end user or the customer or a common person wants to check the agent detail in there locality using(zip code,first name,last name...etc)

When you execute a query on the table you will get set of agents which are in that particular zip code.If the agent list is big , you can show first 10 - 15 agents details on 1st page and remaining details in next pages. Since there is a high probability that the end user will choose the agents which are in 1st page and they will not browse further. Other agents will loose the oppurtunity to get the customer.

In this case we can go for the randomiztion logic , each time u execute a query u get a same results in different order.

Hope this helps!!!!
Valenteno123
 
Posts: 5
Joined: Mon Jul 21, 2008 2:11 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post