I went to an interview with a company today and had an interesting question.

Source: Internet
Author: User
/*
Question  
How to generate 10 thousand numbers, insert them to table t (COL varchar (20), and the numbers cannot be repeated. They can only be retrieved from 26 lower-case letters.
*/

-- 1. Current statement
Select 'A' As Col
Into # T
Union
Select 'B' Union
Select 'C' Union
Select 'D' Union
Select 'E' Union
Select 'F' Union
Select 'G' Union
Select 'H' Union
Select 'I' Union
Select 'J' Union
Select 'K' Union
Select 'L' Union
Select 'M' Union
Select 'N' Union
Select 'O' Union
Select 'P' Union
Select 'Q' Union
Select 'R' Union
Select 'S' Union
Select 'T' Union
Select 'U' Union
Select 'V' Union
Select 'W' Union
Select 'X' Union
Select 'Y' Union
Select 'Z'




Insert Into T
Select Top 10000 a. Col + B. Col + C. Col From # T a, # t B, # T c

Drop Table # T




--------------------------------------------------------------

-- 2. View varchar (20), think of newid (), and then perform some string processing.

Insert Into T
Select Top 10000
Replace (Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace (Lower ( Left ( Replace (Newid (),
'-',''), 20 )),
' 0 ', 'A '),1 ,
'B '), 2 , 'C '), 3 ,
'D '), 4 , 'E '), 5 ,
'F '), 6 , 'G '),7 , 'H '), 8 , 'I '),
9 , 'J ') As Col
From SYS. all_columns,
SYS. all_objects






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.