A database pen questions

1, multiple-choice questions

(1) there are known table T1 in 2 rows, T2 there are three rows of data, execute the SQL statement

"select a. * From T1 a , T2 b" , the number of rows returned to ______

A, 2 row

B, 3 row

C, 5 row

D, row 6

multi-table queries not specify the connection conditions can cause Cartesian product, returns the number of rows is equal to the product of two rows of tables, rows 6 returns

investigated: multi connection table, the Cartesian product of understanding

answer: a

(2), the same as the known field definition table T1 and T2, T1, T2 of each of five different data, wherein at T1 two data exists in the table T2 , the statement "select * from T1 union select * from T2"

number of rows returned to _______

a, row. 8

B, 10 rows

C, 3 row

D, 12 rows

of the second table links after performing UNION question will filter out duplicate recording, so the result set in the table will link the generated sort operation, remove duplicate records and then return the results.

Investigation: UNION understanding

Answer: A

(. 3), the table T1 containing a known field ID, CourseID and Score, and the data is

IDCourseIDScore3190218522903280 the statement "select id, sum (ScorE) from T1 group by ID" is an execution result _________

A, ID SUM

(SCORE) - ----

. 3 170.

2 175

B, ID SUM

(SCORE) - ----

2 175

. 3 170.

C, ID SUM

(SCORE) - ----

2 170.

. 3 175

D, ID SUM (SCORE)

- ----

. 3 175

2 170.

the third question to be grouped gROUP bY ID field, while the same field ID SCORE summing, gROUP by automatically sorted result set so the answer selected B

study: understanding group by the

answer: B

(4), the telephone number list t_phonebook contain one million data, the only index created on the number field PhoneNo, and phone numbers of all the numbers, to count Pier 321 is the number of phone numbers, perform the following wording slowest is _________

A, SELECT COUNT (*) from t_phonebook WHERE PHONENO> = '321' and PHONENO < '321A'

B, SELECT COUNT (*) from t_phonebook WHERE PHONENO like '321%'

C, SELECT COUNT (*) from t_phonebook WHERE the substring ( PHONENO, l, 3) = '321'

A> or <operator will use the index to find

B: lIKE wildcard XXX% in the case of the index will be applied, if the index does not apply in the case of other% xxx%

answer: C: using function handles the field can not use the index, such as substr () this question seems to be written as a function of the java

answer: C

(5), known in the field land_ID tbl table has an index, cust_id field has a unique index, the statement following the same query logic wherein the optimal efficiency is

a, the SELECT * the FROM TBL

the wHERE land_id> 750

or (the cust_id = 180 [or the cust_id = 560.)

B, the SELECT * the FROM TBL

the wHERE (or the cust_id = the cust_id = 180 [560.)

or land_id> 750

C, * the FROM tbl the WHERE land_id the SELECT> 750

UNION

The SELECT * the FROM TBL the WHERE the cust_id = 180 [

the UNION

the SELECT * the FROM TBL the WHERE the cust_id = 560.

D, the SELECT * the FROM TBL the WHERE land_id> 750

the UNION

(the SELECT * the FROM TBL the WHERE the cust_id = 180 [

the UNION ALL

the SELECT * the FROM TBL the WHERE the cust_id = 560.

)

 

C / D comparison, the higher the efficiency of some of the D

UNION making table will filter out duplicate links records, so the result set in the table will link the resulting sort operation to remove duplicate records and then returns the result. Most practical applications will not produce duplicate records

using the alternative operator UNION ALL UNION, UNION ALL operation as simply merge the two results after return.

(6), staff skills table Staffskill structure is as follows, Staff and Skill field has a unique constraint

Staff VARCHAR2 (10),

skill VARCHAR2 (10)

Which statement can query the same time have the skills A and skills B staff

A, select staff from Staffskill where skill = 'A' OR skill = 'B'

B, SELECT Staff from Staffskill WHERE skill = 'A' the AND skill = 'B'

C, SELECT Staff from Staffskill WHERE skill = 'A' OR skill = 'B' Group by Staff

D, SELECT Staff from Staffskill WHERE skill = 'A 'OR skill =' B 'group by staff having count (*)> 1

answer: D

(. 7) employee table staff table is structured as follows

staffNo VARCHAR2 (10),

in Email VARCHAR2 (50)

which a query's SQL statement that no E_mail address employee number

A, the SELECT staffno from staff the WHERE Email = nULL

B, the SELECT staffno from staff the WHERE Email nULL

C, the SELECT staffno from staff the WHERE Email IS null

D, the SELECT staffno from staff the WHERE Email IS not null

answer: C

(8) the Oracle database step boot sequence is

1.Mount 2.Open 3.Nomount

a, 3-1-2

B, 2-3-1

C, 2-1-3

D, 3-2-1

Answer: A

(. 9) the presence of two identical structure of the database tables T1 (col1, col2, col3) , T2 (col1, col2, col3), write a SQL statement to import all the data table T2 T1

a, SELECT col1, col2, col3 from the iNTO T1 T2 (col1, col2, col3)

B, the INSERT T1 (col1, col2, col3) the iNTO T2 (col1 , col2, col3)

C, INSERT INTO T2 (col1, col2, col3) the AS SELECT col1, col2, col3 from Tl;

D, INSERT INTO T2 (col1, col2, col3) SELECT col1, col2, col3 from Tl;

answer: D

field 10) a table of VARCHAR2, if no length specified when building the table, the default length is:

a,. 1

B, 25

C, 38 is

D, 255

E, 4000

F., VARCHAR2 type field must specify the length of time to build the table

answers : F

? (11) with the data in the difference between TRUNCATE and dELETE statement deletes the table

a, TRUNCATE command does not log

B, TRUNCATE command logging

C, DELETE command does not log

Answer: A

(12 is) as the query statement SELECT id_number, 100 / quantity from inventory if the quantity is empty, there is the second field will return statement

A, A Space

B, A null value

C, value of 0 A

D, A 100 value of

E, The keywork null

answer: B

(13 is) the following statement: the SELECT i.id_number, the FROM Inventory m.id_number I, m Manufacturer

the WHERE i.manufacturer_id = m.id_number

the Order by Inventory. description

when execution is wrong, I ask the following measures which can correct this error?

a in order by clause to use an alias table

B in the where clause to remove the table aliases

instead of table in where clause with the table name of C alias

D by clause to remove the table name in order, as long as the field name to

(if two tables, does not exist field named description, then, D answer is correct)

answer: a

14) a table field a type int there 100 records values of 1 to 100. The following statement

The FROM A A the SELECT

the WHERE the BETWEEN A 50. 1 the AND

OR (the IN A (25,70,95)

the AND 25 the BETWEEN A the AND 75)

the value of which follows in the result returned by the sql statement

A, 30 B, 51 C, 75 D , 95

answer: A

? 15) variable v_time = '23 -MAY-00 ', as the return value of that statement -JAN-00 '01'

A the SELECT the ROUND (v_TIME, 'DAY') the FROM the DUAL;

B the SELECT the ROUND ( V_TIME, 'YEAR') the FROM the DUAL;

C the SELECT the ROUND (V_TIME, 'MONTH') the FROM the DUAL;

D the SELECT the ROUND (the TO_CHAR (V_TIME, 'YYYY')) the FROM the DUAL;

answer: B

16) statement on an index (index) of What is wrong?

a, create the index can improve the performance of data insertion

B, the index should be created according to the specific needs of retrieval, create an index and good selectivity column

C, the index is not better

D, indexing allows retrieval operation more quickly

answers: a

(17) pointed out the error of the following sql statement:

SELECT ID_NUMBER "Part Number The", SUM (. price) ". price" from Inventory

WHERE. price> 50

Group by "Part Number The"

Order by 2;

A, Order by 2

B, from Inventory

C, WHERE. price> 50

D, Group by " Part Number "

answer: D

(18 is) following statement

IF v_num>. 5 the then

v_example: =. 1;

ELSIF v_num> 10 the then

v_example: = 2;

ELSIF v_num <20 is the then

v_example: =. 3;

ELSIF v_num <39 the then

v_example: =. 4 ;

the else v_example: =. 5;

if v_num = 37, then the value is the number v_example?

a, B. 1, C 2,. 3 D, E. 4,. 5

answer: a

(. 19) the following statement:

the begin

Loop I in 1..8 for

IF I = 2 the then

null;

the else

IF. 5 I = the then

ROLLBACK;

the else

IF = I. 8 the then

the commit;

the else

INSERT INTO texample (A) values (I);

End IF;

End IF;

End IF;

End Loop;

the commit;

End;

after execution of the statement has several records into the table the table texample?

a = 2. 1 B = C = D =. 3. 4

answer: B

(20 is) designed a table structure, a field requirements store employee numbers, fixed 10 characters long, what type of field using

A, CHAR

B, lONG

C, VARCHAR

D, VARRAY

answer: A

Second, fill in the blank programming problem

(1), T1 comprises a field ID is known, ID2, T2 field contains an ID, in the blank to complete the SQL statement, the lookup table T1 value is present in the ID2 field ID value set in T2.

* from Tl WHERE A SELECT ______ (B SELECT * WHERE b.id from T2 = A.ID2)

SELECT * WHERE A a.id from Tl (SELECT ID from T2 B) ______

SELECT * from A. A Tl, T2 WHERE B A.ID2 ______ b.ID

answer:. 1) in ID2 2). 3) =

SELECT * WHERE A from Tl _ Exists_____ (SELECT * WHERE b.id from T2 = A.ID2 B)

SELECT * WHERE A a.id from Tl __in____ (SELECT ID from T2 B)

SELECT * from A. a Tl, T2 = B WHERE A.ID2 __ ____ b.id

(2) when creating the Oracle table specifies the following parameters is stored:

Initial 50K

Next 2OK

pctincrease 10

then this the third table space allocated for the expansion __________

answer: 22k

(3), a known table T1 contains a field ID, an ID of the same value, there may be a plurality of data, in the blank to complete the SQL statement, the query corresponding to T1 has a section larger than data ID and its corresponding data number.

select ID, count (*) from T1 group by ID ___________________

Answer: the HAVING COUNT (*)>. 1

(. 4), known in tables T1, T2 and T3 and the following data structure

Tl

NameIDCourseIDScore1190128521752295T2

IDCourse1 Mathematics 2 languages T3

IDName1 Zhang 2 John Doe Please write SQL statements to query, making the result of the query is:

the Name Course, Score

--- --- ---

Joe Smith 90 mathematics

Joe Smith 85 languages

Doe mathematics 75

John Doe 95 languages

answer: select Name, Course , Score from Tl, T2, T3 and T1.CourseID WHERE T3.ID = T1.NameID t2.ID =

(. 5), lending to the daily statistics and the number of library books also defines tables T1, the following structure

Field Name Type Description DateStrvarchar (10) Date OprTypeinteger operation type, by 0 for, 1 for the number of operations is also known OprCountinteger table has no data, write a stored procedure to update the table T1, or each further lend books operations call the stored procedure to update statistics, input parameters are: operating time, type of operation.

Answer (T-the SQL):

- using the stored procedure look to see the date and type of operation there is no data, if not then data is inserted, if the update data so that the number of operations increase. 1

Create or Replace Procedure update_pro (v_DateStr in VARCHAR, v_OprType in Integer) AS

vv_DateStr T1.DateStr% type;

vv_OprType T1.OprType% type;

cursor my_cursor IS (SELECT datestr, OprType, OprCount from Tl WHERE datestr = v_DateStr and OprType = v_OprType); - the cursor is declared

the begin

Open my_cursor;

FETCH INTO vv_DateStr my_cursor , vv_OprType;

IF my_cursor% NOTFOUND the then

INSERT INTO Tl (datestr, OprType, OprCount) values (v_DateStr, v_OprType,. 1);

the else

Update T1 SET OprCount = OprCount +. 1 WHERE datestr = v_DateStr and OprType = v_OprType;

End IF;

the commit;

Close my_cursor;

End;

(. 6), the table T1 has a field Field1, type varchar (20), create on T1 a constraint to ensure that the value of the first three characters of Field1 as "aaa", "bbb" or "ccc".

Answer: The answer: the ALTER TABLE T1

the ADD CONSTRAINTS CHK_FILED CHECK (Field1 like'aaa% 'or Field1 like

' bbb% 'or Field1 like' ccc% ');

can not think of a more concise expression, and perhaps achieve better paid

(7), a large mall has a database log table t_Log, it records the transaction log daily commodities, t_Log generation time field contains LogDatetime logging, daily log data between 20,000-40,000 strip. Log table after the discovery of the amount of data is too large, you need to delete the history log data six months ago about 3,000,000 rows. Please consider factors such as performance, delete the historical data write SQL statements.

The answer (T-SQL): This title application and submit a stored procedure batch delete, delete as follows every time 10000

the Create or the replace Procedure Del_pro AS

v_Boolean Boolean: = to true;

v_count Integer: = 0;

the begin

the while v_Boolean Loop

Delete from t_Log WHERE ADD_MONTHS (LogDateTime,. 6) <SYSDATE and rownum <10000;

the commit;

SELECT COUNT (*) INTO v_count from t_log WHERE ADD_MONTHS (LogDateTime,. 6) <SYSDATE;

IF v_count the then 0 =

v_Boolean = to false;

End IF;

End Loop;

End;

larger than the case where the data can be considered a batch delete, efficiency will be higher. Loop control statements can be used, the use of rownum <10000 to 300 points to delete. Note that after each commit deleted.

(8), please write several components of the oracle of the SGA area (only write four main parts can be).

The answer: Shared pool (the shared pool), DataBase Buffer Cache (data buffer)

Redo the Log Buffer (redo log buffer), Large Pool

(9), please write area management (EXTENT MANAGEMENT) two ORACLE database table space ways.

Answer: The dictionary management and local management

(10), please write a few operations you need to know the sort of DML.

Select statement

Order by

addition in the query where clause, try not to judge the function on the left

 

Published 142 original articles · won praise 44 · views 60000 +

Guess you like

Origin blog.csdn.net/weixin_40916641/article/details/102060651