0

I'm creating this function that supposed to return a random string:

create function createRandomString() returns Text
        return concat( 
        char(round(rand()*25)),
        char(round(rand()*25)),
        char(round(rand()*25)),
        char(round(rand()*25)),
        char(round(rand()*25)),
        char(round(rand()*25)),
        char(round(rand()*25)),
        char(round(rand()*25))
    );    

For some reason this function return nothing... i don't know why..

When i'm using the exact same concat() inside a select - it works.

1 Answer 1

1

The problem is that you are returning numeric values between 0 and 25, which are not normal characters to put into a string. Add 65 to them to start at 'A':

create function createRandomString() returns Text
        return concat( 
        char(round(rand()*25+65)),
        char(round(rand()*25+65)),
        char(round(rand()*25+65)),
        char(round(rand()*25+65)),
        char(round(rand()*25+65)),
        char(round(rand()*25+65)),
        char(round(rand()*25+65)),
        char(round(rand()*25+65))
    );

You might want to read up on ASCII coding as well, so you better understand what you are doing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.