Oracle Database Development interview question, when a written test did not come out, now attached to the original question and answer

Source: Internet
Author: User

1.

Id
1
2
3
5
6
7
8
10
11
12
15

Table name TT, using SQL to find the IDs in the ID column, for example, 4:

--Creating tables and DataCREATE TABLETT (IDINTEGER);INSERT  intoTTSELECT 1  fromDualUNION  AllSELECT 2  fromDualUNION  AllSELECT 3  fromDualUNION  AllSELECT 5  fromDualUNION  AllSELECT 6  fromDualUNION  AllSELECT 7  fromDualUNION  AllSELECT 8  fromDualUNION  AllSELECT Ten  fromDualUNION  AllSELECT  One  fromDualUNION  AllSELECT  A  fromDualUNION  AllSELECT  the  fromdual;COMMIT;

--use the Connect by level to create data withIT as (SELECT  LevelId fromDUAL CONNECT by  Level <=(SELECT MAX(ID) fromTT))SELECTa.id fromIT AWHERE  not EXISTS(SELECT 1  fromTT BWHEREa.ID=b.ID)

2.

Organize the irregular room information into canonical format

Non-canonical table (multiple rooms separated by commas)

Id The
1 101,102
2 201,202,203
3 301
.......

Specification table

Id The
1 101
1 102
2 201
2 202
2 203
3 301
......

--Single row to multiple lines--Creating tables and DataCreate TableTTT (IDinteger, thevarchar2( $));Insert  intoTTTSelect 1,'101,102'  fromDualUnion  AllSelect 2,'201,202,203'  fromDualUnion  AllSelect 3,'301'  fromdual;Commit;
SELECT DISTINCTId,regexp_substr (Hostel,'[^,]+',1, Level,'I') as STR     fromTttconnect by  Level <=LENGTH (Guest)-LENGTH (Regexp_replace,',',"'))+1;

Oracle Database Development interview question, when a written test did not come out, now attached to the original question and answer

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.