1. 程式人生 > >ocp 1Z0-051 23-70題解析

ocp 1Z0-051 23-70題解析

23. Examine thestructure proposed for the TRANSACTIONS table:

name Null Type

TRANS_ID NOT NULLNUMBER(6)

CUST_NAME NOT NULLVARCHAR2(20)

CUST_STATUS NOT NULLCHAR

TRANS_DATE NOT NULL DATE

TRANS_VALIDITY VARCHAR2

CUST_CREDIT_LIMIT NUMBER

Which statements aretrue regarding the creation and storage of data in the above table structure?

(Choose all that apply.)

A. The CUST_STATUScolumn would give an error.

B. The TRANS_VALIDITYcolumn would give an error.

C. The CUST_STATUScolumn would store exactly one character.

D. The CUST_CREDIT_LIMITcolumn would not be able to store decimal values.

E. The TRANS_VALIDITY columnwould have a maximum size of one character.

F. The TRANS_DATE columnwould be able to store day, month, century, year, hour, minutes, seconds,

and fractions ofseconds.

Answer: BC

解析:
引用官方文件:

The default length for a CHAR column is 1 byte and themaximum allowed is 2000

bytes. A 1-byte stringcan be inserted into a CHAR(10) column, but the string is

blank-padded to 10 bytesbefore it is stored.

所以C正確,A錯誤

You mustspecify a maximum length for a VARCHAR2 column.This maximum must be

at least 1 byte, althoughthe actual string stored is permitted to be a zero-length string

('').

所以B正確,E錯誤

引用官方文件的一個表格:

Actual Data Specified AsStored As

123.89 NUMBER 123.89

測試:

[email protected]>createtable zbcxy(id number);

表已建立。

[email protected]>insertinto zbcxy values(123.68);

已建立 1 行。

[email protected]>select *from zbcxy;

        ID

----------

123.68

D選項錯誤

The DATE data typestores date and time information. Although date and time

information can berepresented in both character and number data types, the DATE

data type has specialassociated properties. For each DATE value, Oraclestores the

followinginformation: year, month, day, hour, minute, and second.

選項F錯誤

24. Examine thestructure proposed for the TRANSACTIONS table:

name Null Type

TRANS_ID NOT NULL NUMBER(6)

CUST_NAME NOT NULLVARCHAR2(20)

CUST_STATUS NOT NULLVARCHAR2

TRANS_DATE NOT NULL DATE

TRANS_VALIDITY INTERVALDAY TO SECOND

CUST_CREDIT_VALUENUMBER(10)

Which two statements aretrue regarding the storage of data in the above table structure? (Choose two.)

A. The TRANS_DATE columnwould allow storage of dates only in the dd-mon-yyyy format.

B. The CUST_CREDIT_VALUEcolumn would allow storage of positive and negative integers.

C. The TRANS_VALIDITYcolumn would allow storage of a time interval in days, hours, minutes, and

seconds.

D. The CUST_STATUScolumn would allow storage of data up to the maximum VARCHAR2 size of 4,000

characters.

Answer: BC

解析:
A選項中可以使用to_char設定多種格式

引用官方文件:

The NUMBER data typestores zero as well as positive and negativefixed numbers with

absolute values from 1.0x 10-130 to but not including 1.0 x 10126.

所以B正確

INTERVAL DAY TO SECONDstores a period of time in terms of days, hours,minutes,

and seconds. This data type is useful for representing the precisedifference between

two datetime values.

所以C正確

D選項根據上題可知,使用varchar型別,必須指定長度,所以D選項錯誤

25. You need to create atable with the following column specifications:

1. Employee ID (numericdata type) for each employee

2. Employee Name(character data type) that stores the employee name

3. Hire date, whichstores the date of joining the organization for each employee

4. Status (characterdata type), that contains the value 'ACTIVE' if no data is entered

5. Resume (characterlarge object [CLOB] data type), which contains the resume submitted by the

employee

Which is the correctsyntax to create this table?

A. CREATE TABLE EMP_1

(emp_id NUMBER(4),

emp_name VARCHAR2(25),

start_date DATE,

e_status VARCHAR2(10)DEFAULT 'ACTIVE',

resume CLOB(200));

B. CREATE TABLE 1_EMP

(emp_id NUMBER(4),

emp_name VARCHAR2(25),

start_date DATE,

emp_status VARCHAR2(10)DEFAULT 'ACTIVE',

resume CLOB);

C. CREATE TABLE EMP_1

(emp_id NUMBER(4),

emp_name VARCHAR2(25),

start_date DATE,

emp_status VARCHAR2(10)DEFAULT "ACTIVE",

resume CLOB);

D. CREATE TABLE EMP_1

(emp_id NUMBER,

emp_name VARCHAR2(25),

start_date DATE,

emp_status VARCHAR2(10)DEFAULT 'ACTIVE',

resume CLOB);

Answer: D

解析:

引用官方文件:

The CLOB data typestores single-byte and multibyte character data. Both fixed-width

and variable-widthcharacter sets are supported, and both use the database character set

使用clob無需指定長度,所以A錯

B選項 表名不能以數字開頭

C選項 default 用單引號

所以D正確

26. Which is the validCREATE TABLE statement?

A. CREATE TABLE emp9$#(emp_no NUMBER (4));

B. CREATE TABLE 9emp$#(emp_no NUMBER(4));

C. CREATE TABLE emp*123(emp_no NUMBER(4));

D. CREATE TABLE emp9$#(emp_no NUMBER(4), date DATE);

Answer: A

解析:
建立表時,表的名稱必須是合法標示符,長度為1-30位元組,並且以字母開頭,可以包含字母,數字,下劃線,美元符號和#,此外表名稱不能與所屬模式中其他物件同名,也不能是oracle資料庫的保留字

由此判斷B和C錯誤

D選項不能使用oracle中關鍵字作為屬性名稱

所以A正確

27. Which two statementsare true regarding tables? (Choose two.)

A. A table name can beof any length.

B. A table can have anynumber of columns.

C. A column that has aDEFAULT value cannot store null values.

D. A table and a viewcan have the same name in the same schema.

E. A table and a synonymcan have the same name in the same schema.

F. The same table namecan be used in different schemas in the same database.

Answer: EF

根據上題所知,表名的長度在1-30位元組,所以A選項錯誤

B選項,測試:

BEGIN

FOR I IN 1..999 LOOP

EXECUTE IMMEDIATE 'ALTERTABLE zbcxy ADD id' || I || ' NUMBER(1)';

END LOOP;

END;

[email protected]>altertable zbcxy add id1000 number(1);

alter table zbcxy addid1000 number(1)

                      *

第 1 行出現錯誤:

ORA-01792: 表或檢視中的最大列數為 1000

可知oracle限制最大列數為1000,所以B選項錯誤

C選項,測試:

[email protected]>createtable zbcxy(name varchar(20) default 'zbcxy');

表已建立。

[email protected]>insertinto zbcxy values(' ');

已建立 1 行。

[email protected]>select *from zbcxy;

NAME

所以C選項錯誤

D選項,一個模式下面的物件是不能同名的,所以D選項錯誤

E選項,測試:

[email protected]>createpublic synonym emp for emp;

同義詞已建立。

[email protected]>createsynonym dept for dept;

create synonym dept fordept

*

第 1 行出現錯誤:

ORA-01471: 無法建立與物件同名的同義詞

這裡題意估計是指的公共的

所以E選項正確

F選項,不同模式下可以有同名的物件

28. Which two statementsare true regarding constraints? (Choose two.)

A. A foreign key cannot containNULL values.

B. A column with theUNIQUE constraint can contain NULL values.

C. A constraint isenforced only for the INSERT operation on a table.

D. A constraint can bedisabled even if the constraint column contains data.

E. All constraints can bedefined at the column level as well as the table level.

Answer: BD

解析:
選項A,如果參照表中有空值,則外來鍵也可以為空值,可以採用

Insert into zbcxy valuesselecet ename from emp;這種方式將emp中ename的控制插入到zbcxy表中

所以選項A是錯誤的

B選項,很明顯unique約束時可以是空值,這裡就不演示測試了

C選項,明顯錯誤,不止insert ,執行update操作也是必須遵守約束的

D選項,測試:
[email protected]>create table zbcxy(id number(4) constraint p_pk primary key);

表已建立。

[email protected]>insertinto zbcxy values(1);

已建立 1 行。

[email protected]>altertable zbcxy disable constraint p_pk;

表已更改。

所以D選項正確

E選項,非空約束只能定義列級約束,所以E選項是錯誤的

29. Which two statementsare true regarding constraints? (Choose two.)

A. A foreign key cannotcontain NULL values.

B. The column with aUNIQUE constraint can store NULLS .

C. A constraint isenforced only for an INSERT operation on a table.

D. You can have morethan one column in a table as part of a primary key.

Answer: BD

解析:

A選項,由上題可知是錯誤的

B選項,由上題可知是正確的

C選項,由上題可知是錯誤的

D選項,一個表中只能有雖然只有一個約束,但是可以建立一個聯合主鍵約束,這樣就有多列為主鍵約束,所以D選項正確

30. Evaluate thefollowing CREATE TABLE commands:

CREATE TABLE orders

(ord_no NUMBER(2)CONSTRAINT ord_pk PRIMARY KEY,

ord_date DATE,

cust_id NUMBER(4));

CREATE TABLE ord_items

(ord_no NUMBER(2),

item_no NUMBER(3),

qty NUMBER(3) CHECK (qtyBETWEEN 100 AND 200),

expiry_date date CHECK(expiry_date > SYSDATE),

CONSTRAINT it_pk PRIMARYKEY (ord_no,item_no),

CONSTRAINT ord_fkFOREIGN KEY(ord_no) REFERENCES orders(ord_no));

The above command failswhen executed. What could be the reason?

A. SYSDATE cannot beused with the CHECK constraint.

B. The BETWEEN clausecannot be used for the CHECK constraint.

C. The CHECK constraintcannot be placed on columns having the DATE data type.

D. ORD_NO and ITEM_NOcannot be used as a composite primary key because ORD_NO is also the

FOREIGN KEY.

Answer: A

解析:

[email protected]>CREATETABLE ord_items

  2 (ord_no NUMBER(2),

  3 item_no NUMBER(3),

  4  qtyNUMBER(3) CHECK (qty BETWEEN 100 AND 200),

  5 expiry_date date CHECK (expiry_date > SYSDATE),

  6 CONSTRAINT it_pk PRIMARY KEY (ord_no,item_no),

  7 CONSTRAINT ord_fk FOREIGN KEY(ord_no) REFERENCES orders(ord_no));

expiry_date date CHECK(expiry_date > SYSDATE),

                                      *

第 5 行出現錯誤:

ORA-02436: 日期或系統變數在 CHECK 約束條件中指定錯誤

所以A選項正確

31. Evaluate thefollowing SQL commands:

SQL>CREATE SEQUENCEord_seq

INCREMENT BY 10

START WITH 120

MAXVALUE 9999

NOCYCLE;

SQL>CREATE TABLEord_items

(ord_no NUMBER(4)DEFAULTord_seq.NEXTVAL NOT NULL,

item_no NUMBER(3),

qty NUMBER(3) CHECK (qtyBETWEEN 100 AND 200),

expiry_date date CHECK(expiry_date > SYSDATE),

CONSTRAINT it_pk PRIMARYKEY (ord_no,item_no),

CONSTRAINT ord_fkFOREIGN KEY(ord_no) REFERENCES orders(ord_no));

The command to create atable fails. Identify the reason for the SQL statement failure? (Choose allthat

apply.)

A. You cannot useSYSDATE in the condition of a CHECK constraint.

B. You cannot use theBETWEEN clause in the condition of a CHECK constraint.

C. You cannot use theNEXTVAL sequence value as a DEFAULT value for a column.

D. You cannot use ORD_NOand ITEM_NO columns as a composite primary key because ORD_NO is

also the FOREIGN KEY.

Answer: AC

解析:

[email protected]>CREATETABLE ord_items

  2 (ord_no NUMBER(4)DEFAULT ord_seq.NEXTVAL NOT NULL,

  3 item_no NUMBER(3),

  4  qtyNUMBER(3) CHECK (qty BETWEEN 100 AND 200),

  5 expiry_date date CHECK (expiry_date > SYSDATE),

  6 CONSTRAINT it_pk PRIMARY KEY (ord_no,item_no),

  7 CONSTRAINT ord_fk FOREIGN KEY(ord_no) REFERENCES orders(ord_no));

(ord_no NUMBER(4)DEFAULTord_seq.NEXTVAL NOT NULL,

                         *

第 2 行出現錯誤:

ORA-00984: 列在此處不允許

由上題可知A選項正確,B,D選項錯誤,經上面測試,C選項正確

32. Which CREATE TABLEstatement is valid?

A. CREATE TABLEord_details

(ord_no NUMBER(2)PRIMARY KEY,

item_no NUMBER(3)PRIMARY KEY,

ord_date DATE NOT NULL);

B. CREATE TABLEord_details

(ord_no NUMBER(2)UNIQUE, NOT NULL,

item_no NUMBER(3),

ord_date DATE DEFAULTSYSDATE NOT NULL);

C. CREATE TABLEord_details

(ord_no NUMBER(2) ,

item_no NUMBER(3),

ord_date DATE DEFAULTNOT NULL,

CONSTRAINT ord_uq UNIQUE(ord_no),

CONSTRAINT ord_pkPRIMARY KEY (ord_no));

D. CREATE TABLEord_details

(ord_no NUMBER(2),

item_no NUMBER(3),

ord_date DATE DEFAULTSYSDATE NOT NULL,

CONSTRAINT ord_pkPRIMARY KEY (ord_no, item_no));

Answer: D

解析:

A選項:一個表中不能有兩個主鍵

B選項:約束那裡語法錯誤

C選項:default用法錯誤,以及一個列不能同時附加兩個唯一約束,測試:

[email protected]>create table zbcxy(id number(2),
  2  constraint p_idu unique(id),
  3  constraint p_idk primary key(id)
  4  );
constraint p_idu unique(id),
                 *
第 2 行出現錯誤:
ORA-02261: 表中已存在這樣的唯一關鍵字或主鍵

D選項正確

33. You want to createan ORD_DETAIL table to store details for an order placed having the following

business requirement:

1) The order ID will beunique and cannot have null values.

2) The order date cannothave null values and the default should be the current date.

3) The order amountshould not be less than 50.

4) The order status willhave values either shipped or not shipped.

5) The order paymentmode should be cheque, credit card, or cash on delivery (COD).

Which is the valid DDLstatement for creating the ORD_DETAIL table?

A. CREATE TABLEord_details

(ord_id NUMBER(2)CONSTRAINT ord_id_nn NOT NULL,

ord_date DATE DEFAULTSYSDATE NOT NULL,

ord_amount NUMBER(5, 2)CONSTRAINT ord_amount_min

CHECK (ord_amount >50),

ord_status VARCHAR2(15)CONSTRAINT ord_status_chk

CHECK (ord_status IN('Shipped', 'Not Shipped')),

ord_pay_modeVARCHAR2(15) CONSTRAINT ord_pay_chk

CHECK (ord_pay_mode IN('Cheque', 'Credit Card',

'Cash On Delivery')));

B. CREATE TABLEord_details