cancel
Showing results for 
Search instead for 
Did you mean: 

SQLScript - random function

Former Member
0 Kudos

Hi,

Am I wrong or there is no random function in SQLScript? There is a series of math function, but random would quite useful especially when generating test data.

If it is not included now, will it be planned in next releases?

Regards,

Adam

Accepted Solutions (1)

Accepted Solutions (1)

tomas-krojzl
Active Contributor
0 Kudos

Hello,

there is no such function mentioned anywhere in SQL reference guide (at the moment) - so I guess it is not available... but you can implement yourself - technically random function does not exist - it is always complex function seeded by current time (where current time is making it "random")

You can find more information here:

http://en.wikipedia.org/wiki/Random_number_generation

Alternative is to way few days - maybe it will be available when SP03 will be out.

Tomas

Answers (3)

Answers (3)

former_member200930
Participant
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

I would really look forward to having a good random generator built in HANA. Finally I have created a very pseudo random generator, but it fits my needs. Code is like this:

number := mod((8253729 * EXTRACT(SECOND from NOW()) * EXTRACT(MINUTE from NOW()) + random_seq.nextval), 100);

where random_seq is just a sequence starting at 1, no cycles. Produces sort of random integer numbers less then 100. Also sequence is not entered directly.

Thanks for input.

Edited by: Adam Podraza on Nov 4, 2011 3:51 PM

Former Member
0 Kudos

Hello, Adam!

Its very helpful, but i have some error with your code.

The error look like "invalid sequence: RANDOM_SEQ".

Can you advice me how to solve this problem?

Regards, Dmtiry

Former Member
0 Kudos

Hi Dmitry

    You need to create the sequence of your own , option to create sequence is available under your schema .

Regards

Santosh