Oracle random number, random date and time, random string

Source: Internet
Author: User

1. Random Number package

SELECT DBMS_RANDOM.VALUE
From dual;

2. Random Number in the range of [0 .. 100]

Select trunc (DBMS_RANDOM.VALUE (0,100 ))
From dual;

3. A 10-character random string larger than 'A'

SELECT DBMS_RANDOM.STRING ('A', 10)
From dual;

4. A single lowercase random character

Select chr (ROUND (DBMS_RANDOM.VALUE (97,122 )))
From dual;

5. Get the random date in the past 10 days

SELECT TO_DATE (TRUNC (DBMS_RANDOM.VALUE (TO_NUMBER (TO_CHAR (SYSDATE-10,
'J'
)
),
TO_NUMBER (TO_CHAR (SYSDATE, 'J '))
)
),
'J'
)
From dual;

 

6. Random Time in the past 30 minutes

SELECT (SYSDATE-1/24/60*30) + DBMS_RANDOM.VALUE (1, 1800)/3600/24
From dual;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.