1. You need to load information about new customers from the NEW_CUST table into the tables CUST and CUST_SPECIAL. If a new customer has a credit limit greater than 10,000, then the details have to be inserted into CUST_SPECIAL. All new customer details have to be inserted into the CUST table. Which technique should be used to load the data most efficiently?
A. external table
B. the MERGE command
C. the multitable INSERT command
D. INSERT using WITH CHECK OPTION
答案: C
分析: 本題考點是multitable INSERT
題目要求將NEW_CUST表上所有的記錄插入CUST表,credit limit大於10000的記錄要同時插入CUST_SPECIAL表,應該使用有條件的insert命令,sql如下:
insert all
when credit_limit>=10000 into CUST_SPECIAL
when 1=1 into CUST
A. 外部表是只讀的,不能進行插入操作
B. merge命令只能針對一張表進行插入或者修改操作,不能針對多張表進行插入操作
D. insert命令沒有with check option選項,with check option選項是create view時使用的
2. View the Exhibit and examine the description of the CUSTOMERS table. You want to add a constraint on the CUST_FIRST_NAME column of the CUSTOMERS table so that the value inserted in the column does not have numbers. Which SQL statement would you use to accomplish the task?
A. ALTER TABLE CUSTOMERS ADD CONSTRAINT cust_f_name CHECK(REGEXP_LIKE(cust_first_name,'^AZ')) NOVALIDATE;
B. ALTER TABLE CUSTOMERS ADD CONSTRAINT cust_f_name CHECK(REGEXP_LIKE(cust_first_name,'^[09]')) NOVALIDATE;
C. ALTER TABLE CUSTOMERS ADD CONSTRAINT cust_f_name CHECK(REGEXP_LIKE(cust_first_name,'[[:alpha:]]'))NOVALIDATE;
D. ALTER TABLE CUSTOMERS ADD CONSTRAINT cust_f_name CHECK(REGEXP_LIKE(cust_first_name,'[[:digit:]]'))NOVALIDATE;
答案: C
分析: 本題考點是正則表達式/REGEXP
要在表CUSTOMERS的字段CUST_FIRST_NAME建個約束,使這個字段不能包含數字
A. 匹配開頭是AZ的字符串。
B. 匹配開頭是0或者是9的字符串。
C. 匹配包含字母的字符串。
D. 匹配包含數字的字符串。
3. Which three tasks can be performed using regular expression support in Oracle Database 10g? (Choose three.)
A. It can be used to concatenate two strings.
B. It can be used to find out the total length of the string.
C. It can be used for string manipulation and searching operations.
D. It can be used to format the output for a column or expression having string data.
E. It can be used to find and replace operations for a column or expression having string data.
答案: CDE
分析: 本題考點是正則表達式/REGEXP
Oracle 10g支持正則表達式的函數主要有REGEXP_LIKE、REGEXP_INSTR、REGEXP_SUBSTR、REGEXP_REPLACE,用來尋找或替換匹配的字符串
A. 連接兩個字符串用符號||,正則表達式沒有這個功能。
B. 字符串的長度是用length()函數,正則表達式沒有這個功能。
4. View the Exhibit and examine the structure of the EMP table which is not partitioned and not an indexorganized table. Evaluate the following SQL statement:
ALTER TABLE emp DROP COLUMN first_name;
Which two statements are true regarding the above command? (Choose two.)
A. The FIRST_NAME column would be dropped provided it does not contain any data.
B. The FIRST_NAME column would be dropped provided at least one or more columns remain in the table.
C. The FIRST_NAME column can be rolled back provided the SET UNUSED option is added to the above SQL statement.
D. The FIRST_NAME column can be dropped even if it is part of a composite PRIMARY KEY provided the CASCADE option is used.
答案: BD
分析: 本題考點是set unused
EMP表不是分區表也不是所引組織表,drop columns是物理刪除,set unused是邏輯刪除,兩者都不可以通過rollback恢復,所有引用到該列的對象都會失敗。
A. 不管列上有沒有數據,刪除列的命令都可以正常執行。
C. set unused的列無法訪問,無法使用rollback撤銷unused設置
5. Evaluate the CREATE TABLE statement:
CREATE TABLE products (product_id NUMBER(6) CONSTRAINT prod_id_pk PRIMARY KEY, product_name VARCHAR2(15));
Which statement is true regarding the PROD_ID_PK constraint?
A. It would be created only if a unique index is manually created first.
B. It would be created and would use an automatically created unique index.
C. It would be created and would use an automatically created nonunique index.
D. It would be created and remains in a disabled state because no index is specified in the command.
答案: B
分析: 本題考點是主鍵約束和唯一性約束自動建立索引
Oracle在創建主鍵約束或唯一性約束時,會自動檢測該列是否創建過唯一性索引,如果有則不創建而直接使用,如果沒有則自動隱式創建唯一性索引。
A. 創建主鍵約束不需要首先手動創建唯一性索引,Oracle會自動隱式創建唯一性索引
C. 創建主鍵約束時,Oracle會自動隱式創建的索引是唯一性索引
D. 創建主鍵約束時沒有指定索引,Oracle會自動尋找唯一性索引,找不到則會自動創建唯一性索引。所有約束創建時默認都是自動生效的
6. Which two statements are true? (Choose two.)
A. The USER_SYNONYMS view can provide information about private synonyms.
B. The user SYSTEM owns all the base tables and useraccessible views of the data dictionary.
C. All the dynamic performance views prefixed with V$ are accessible to all the database users.
D. The USER_OBJECTS view can provide information about the tables and views created by the user.
E. DICTIONARY is a view that contains the names of all the data dictionary views that the user can access.
答案: AE
分析: 本題考點是數據字典/data dictionary
B. system用戶是操作系統管理員,sys才是數據庫管理員,數據字典的所有基表和視圖都屬於sys用戶。
C. v$為前綴的動態性能視圖要有DBA權限才能訪問。
D. USER_OBJECTS視圖不僅包含用戶的表、視圖信息,還包括了其他對象如觸發器、索引、過程等等。
7. View the Exhibit and examine the description of the ORDERS table. Which two WHERE clause conditions demonstrate the correct usage of conversion functions? (Choose two.)
A. WHERE order_date > TO_DATE('JUL 10 2006','MON DD YYYY')
B. WHERE TO_CHAR(order_date,'MON DD YYYY') = 'JAN 20 2003'
C. WHERE order_date > TO_CHAR(ADD_MONTHS(SYSDATE,6),'MON DD YYYY')
D. WHERE order_date IN ( TO_DATE('Oct 21 2003','Mon DD YYYY'), TO_CHAR('NOV 21 2003','Mon DD YYYY') )
D. WHERE order_date IN ( TO_DATE('Oct 21 2003','Mon DD YYYY'), TO_CHAR('NOV 21 2003','Mon DD YYYY') )
答案: AB
分析: 本題考點是日期格式/date type
C. order_date是timestamp with local timezone數據類型,TO_CHAR(ADD_MONTHS(SYSDATE,6),'MON DD YYYY')返回的是字符串,如果不符合系統時間格式則Oracle無法隱式轉換,兩者比較時會出錯。
D. in是集合操作符,集合中TO_DATE('Oct 21 2003','Mon DD YYYY')返回date格式,TO_CHAR('NOV 21 2003','Mon DD YYYY')返回字符串,數據類型不一致。
8. View the Exhibit and examine the description of the EMPLOYEES table. Your company decided to give a monthly bonus of $50 to all the employees who have completed five years in the company. The following statement is written to display the LAST_NAME, DEPARTMENT_ID, and the total annual salary:
SELECT last_name, department_id, salary+50*12 "Annual Compensation" FROM employees WHERE MONTHS_BETWEEN(SYSDATE, hire_date)/12 >= 5;
When you execute the statement, the "Annual Compensation" is not computed correctly. What changes would you make to the query to calculate the annual compensation correctly?
A. Change the SELECT clause to SELECT last_name, department_id, salary*12+50 "Annual Compensation".
B. Change the SELECT clause to SELECT last_name, department_id, salary+(50*12) "Annual Compensation".
C. Change the SELECT clause to SELECT last_name, department_id, (salary+50)*12 "Annual Compensation".
D. Change the SELECT clause to SELECT last_name, department_id, (salary*12)+50 "Annual Compensation".
答案: C
分析: 本題要求為每個工作滿5年的員工的月工資增加$50,返回他們的LAST_NAME、DEPARTMENT_ID和年薪,年薪=(salary+50)*12。
9. Evaluate the following CREATE SEQUENCE statement:
CREATE SEQUENCE seq1 START WITH 100 INCREMENT BY 10 MAXVALUE 200 CYCLE NOCACHE;
The sequence SEQ1 has generated numbers up to the maximum limit of 200. You issue the following SQL statement:
SELECT seq1.nextval FROM dual;
What is displayed by the SELECT statement?
A. 1
B. 10
C. 100
D. an error
答案: A
分析: 本題考點是序列/SEQUENCE
START WITH 100指定序列第一次使用是從100開始,INCREMENT BY 10指定序列每次使用增加10,MAXVALUE 200指定序列最大值為200,CYCLE指定序列可以循環使用,NOCACHE指定序列不使用緩存。序列沒有設置minvalue參數,所以這個序列第一次使用從100開始,每用1次增加10,達到最大值200后循環到minvalue,由於沒有設置minvalue,所以使用默認值1。
10. View the Exhibit and examine the description of the EMPLOYEES table. You want to display the EMPLOYEE_ID, FIRST_NAME, and DEPARTMENT_ID for all the employees who work in the same department and have the same manager as that of the employee having EMPLOYEE_ID 104. To accomplish the task, you execute the following SQL statement:
SELECT employee_id, first_name, department_id FROM employees WHERE (manager_id, department_id) =(SELECT department_id, manager_id FROM employees WHERE employee_id = 104) AND employee_id <> 104
When you execute the statement it does not produce the desired output. What is the reason for this?
A. The WHERE clause condition in the main query is using the = comparison operator, instead of EXISTS.
B. The WHERE clause condition in the main query is using the = comparison operator, instead of the IN operator.
C. The WHERE clause condition in the main query is using the = comparison operator, instead of the = ANY operator.
D. The columns in the WHERE clause condition of the main query and the columns selected in the subquery should be in the same order.
答案: D
分析: 本題考點是組合列
where子句的(manager_id, department_id)作為組合列,要求子查詢返回的也是一個結構相同的組合列,而不是(department_id, manager_id)
11. View the Exhibit and examine the descriptions of ORDER_ITEMS and ORDERS tables. You want to display the CUSTOMER_ID, PRODUCT_ID, and total (UNIT_PRICE multiplied by QUANTITY) for the order placed. You also want to display the subtotals for a CUSTOMER_ID as well as for a PRODUCT_ID for the last six months.
Which SQL statement would you execute to get the desired output?
A. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id GROUP BY ROLLUP (o.customer_id,oi.product_id) WHERE MONTHS_BETWEEN(order_date, SYSDATE) <= 6
B. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id GROUP BY ROLLUP (o.customer_id,oi.product_id) HAVING MONTHS_BETWEEN(order_date, SYSDATE) <= 6
C. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id GROUP BY ROLLUP (o.customer_id, oi.product_id) WHERE MONTHS_BETWEEN(order_date, SYSDATE) >= 6
D. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id WHERE MONTHS_BETWEEN(order_date, SYSDATE) <= 6 GROUP BY ROLLUP (o.customer_id, oi.product_id)
答案: D
分析: 本題考點是WHERE與HAVING的區別
A. where要寫在group by之前
B. having子句中的列要在select子句中出現
C. where要寫在group by之前
12. View the Exhibit and examine the structure of the EMPLOYEES table. You want to retrieve(檢索) hierarchical(分層) data of the employees using the top-down
hierarchy(自上而下的層級). Which SQL clause would let you choose the direction to walk through the hierarchy tree?
A. WHERE
B. HAVING
C. GROUP BY
D. START WITH
E. CONNECT BY PRIOR
答案: E
分析: 本題考點是遞歸查詢
本題要求檢索順序是top-down,即自上而下,從上級到下級的順序,控制遞歸查詢遍歷順序的是CONNECT BY子句,通過PRIOR關鍵字的位置來確定遍歷方向,PRIOR運算符在一側表示父節點,在另一側表示子節點,從而確定查找樹結構是的順序是自頂向下還是自底向上。
A. where用來限制結果集的范圍。
B. having用來限制分組后的結果集的范圍。
C. GROUP BY用來限制結果集的范圍。
D. START WITH用來指定遍歷的起始位置
13. Which two statements are true regarding(關於) the execution of the correlated(相關) subqueries? (Choose two.)
A. The nested query executes after the outer query returns the row.
B. The nested query executes first and then the outer query executes.
C. The outer query executes only once for the result returned by the inner query.
D. Each row returned by the outer query is evaluated for the results returned by the inner query.
答案: AD
分析: 本題考點是相關子查詢/correlated subquery
相關子查詢的執行流程是:
1. 外查詢上拿一行
2. 用外查詢的候選行的值做評估后,內查詢返回了記錄
3. 判斷是否符合外查詢的where條件
4. 反復執行一直到最后
14. OE and SCOTT are the users in the database. The ORDERS table is owned by OE. Evaluate(評價) the statements issued(發行) by the DBA in the following sequence:
CREATE ROLE r1;
GRANT SELECT, INSERT ON oe.orders TO r1;
GRANT r1 TO scott;
GRANT SELECT ON oe.orders TO scott;
REVOKE SELECT ON oe.orders FROM scott;
What would be the outcome after executing the statements?
A. SCOTT would be able to query the OE.ORDERS table.
B. SCOTT would not be able to query the OE.ORDERS table.
C. The REVOKE statement would remove the SELECT privilege from SCOTT as well as from the role R1.
D. The REVOKE statement would give an error because the SELECT privilege has been granted to the role R1.
答案: A
分析: 本題考點是權限/privilege
對象權限可以直接授予用戶,也可以授予角色后將角色授予用戶,結果是用戶都可以使用該權限。但是用戶通過角色獲得的權限不可以被單獨撤銷,需要撤銷角色來撤銷權限。
B. SCOTT擁有r1角色,該角色有OE.ORDERS表的select權限,所以SCOTT仍然能正常查詢該表。
C. revoke命令不會在撤銷一個用戶的權限時,將用戶所屬角色的相同權限一並撤銷,撤銷角色權限必須顯式聲明。
D. revoke命令撤銷的是SCOTT用戶通過GRANT SELECT ON oe.orders TO scott得到的權限,不是通過r1角色得到的權限,所以不會出錯。
15. Evaluate the following SQL statement:
ALTER TABLE hr.emp (HR用戶下的employees表)
SET UNUSED (mgr_id) (manager_id)
Which statement is true regarding the effect of the above SQL statement?
A. Any synonym existing on the EMP table would have to be recreated.
B. Any constraints defined on the MGR_ID column would be removed by the above command.
C. Any views created on the EMP table that include the MGR_ID column would have to be dropped and recreated.
D. Any index created on the MGR_ID column would continue to exist until the DROP UNUSED COLUMNS command is executed.
答案: B
分析: 本題考點是set unused
drop columns是物理刪除,set unused是邏輯刪除,兩者都不可以通過rollback恢復,所有引用到該列的對象都會失敗。
A. 當列被drop或者被set unused時,所有基於該列的對象失效。表的同義詞基於的是表不是列,所以不會失效。
C. 含有被set unused的列的視圖會失效,但不會自動刪除並重建,由於表結構改變,視圖已經無法重建,應該稱為新建視圖。
D. 當set unused或者drop列時,會刪除表的結構被依賴的 index/constrain/trigger,依賴於該表的 procedure/function 將保留,但是變為 invalid 狀態
16. EMPDET is an external table containing the columns EMPNO and ENAME. Which command would work in relation to the EMPDET table?
外部數據表都是只讀的,因此在外部表不能夠執行DML操作,也不能創建索引
A. UPDATE empdet SET ename = 'Amit' WHERE empno = 1234;
B. DELETE FROM empdet WHERE ename LIKE 'J%';
C. CREATE VIEW empvu AS SELECT * FROM empdept;
D. CREATE INDEX empdet_idx ON empdet(empno);
答案: C
分析: 本題考點是外部表/external table
外部數據表是只讀的,只能對外部表執行select操作,insert, update,delete不能執行。外部表的數據不保存在數據庫里,所以不能為外部表創建索引。ANALYZE語句不支持采集外部表的統計數據,應該使用DMBS_STATS包來采集外部表的統計數據。
17. View the Exhibit and examine the structure of the MARKS_DETAILS and MARKStables. Which is the best method to load data from the MARKS_DETAILS table to the MARKStable?
A. Pivoting INSERT
B. Unconditional INSERT
C. Conditional ALL INSERT
D. Conditional FIRST INSERT
答案: A
分析: 本題考點是multitable INSERT
multitable INSERT語句中的Pivoting INSERT方式可以將數據從非關系型數據庫導入到關系型數據庫
18. View the Exhibit and examine the data in ORDERS and ORDER_ITEMS tables. You need to create a view that displays the ORDER ID, ORDER_DATE, and the total number of items in each order. Which CREATE VIEW statement would create the view successfully?
A. CREATE OR REPLACE VIEW ord_vu (order_id,order_date) AS SELECT o.order_id, o.order_date, COUNT(i.line_item_id) "NO OF ITEMS" FROM orders o JOIN order_items i ON (o.order_id = i.order_id) GROUP BY o.order_id,o.order_date
B. CREATE OR REPLACE VIEW ord_vu AS SELECT o.order_id, o.order_date, COUNT(i.line_item_id) "NO OF ITEMS" FROM orders o JOIN order_items i ON (o.order_id = i.order_id) GROUP BY o.order_id,o.order_date
C. CREATE OR REPLACE VIEW ord_vu AS SELECT o.order_id, o.order_date, COUNT(i.line_item_id) FROM orders o JOIN order_items i ON (o.order_id = i.order_id) GROUP BY o.order_id,o.order_date
D. CREATE OR REPLACE VIEW ord_vu AS SELECT o.order_id, o.order_date, COUNT(i.line_item_id)||' NO OF ITEMS' FROM orders o JOIN order_items i ON (o.order_id = i.order_id) GROUP BY o.order_id,o.order_date WITH CHECK OPTION
答案: B
分析: 本題考點是視圖/view
創建視圖的命令格式為:
create or replace view view_name as (select...from...)
A. 視圖的列名是通過select語句指定的。而不是直接指定的。
C. 沒有為COUNT(i.line_item_id)列取別名,別人查看視圖時無法了解該列的含義。
D. ||用來連接2個字符串
19.View the Exhibit and examine PRODUCTS and ORDER_ITEMS tables. You executed the following query to display PRODUCT_NAME and the number of times the product has been ordered:
SELECT p.product_name, i.item_cnt FROM (SELECT product_id, COUNT (*) item_cnt FROM order_items GROUP BY product_id) i RIGHT OUTER JOIN products p ON i.product_id = p.product_id;
What would happen when the above statement is executed?
A. The statement would execute successfully to produce the required output.
B. The statement would not execute because inline views and outer joins cannot be used together.
C. The statement would not execute because the ITEM_CNT alias cannot be displayed in the outer query.
D. The statement would not execute because the GROUP BY clause cannot be used in the inline view.
答案: A
分析: 本題考點是inline view
inline view是指在另一個select語句的from子句中的select語句,In-line views常常通過去除join操作符和將許多單獨的查詢凝聚在一個簡單的查詢里以此來簡化復雜的查詢。
B. inline views可以和outer joins同時使用。
C. 外查詢可以通過表名.列名的形式來調用item_cnt列。
D. inline views中可以使用group by。
20. In which scenario would you use the ROLLUP operator for expression or columns within a GROUP BY clause?
A. to find the groups forming the subtotal in a row
B. to create groupwise grand totals for the groups specified within a GROUP BY clause
C. to create a grouping for expressions or columns specified within a GROUP BY clause in one direction, from right to left for calculating the subtotals
D. to create a grouping for expressions or columns specified within a GROUP BY clause in all possible directions, which is crosstabular report for calculating the subtotals
答案: C
分析: 本題考點是ROLLUP
用了rollup的group by子句所產生的所謂的超級聚合就是指在在產生聚合時會從右向左逐個對每一列進行小結,並在結果中生成獨立的一行,同時也會對聚合列生成一個合計列。
A. ROLLUP會為每個分組進行匯總,不只一行。
B. 會從右向左逐個對每一列進行匯總,不僅僅只有GROUP BY子句中指定的列。
D. 在產生聚合時會從右向左逐個對每一列進行匯總,而不是所有可能的方向。
21. View the Exhibit and examine the details of the EMPLOYEES table.
Evaluate the following SQL statement:
SELECT phone_number,
REGEXP_REPLACE(phone_number,'([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})', '(\1) \2-\3')
"PHONE NUMBER"
FROM employees?
The query was written to format the PHONE_NUMBER for the employees. Which option would be the
correct format in the output?
REGEXP_REPLACE( 字符串 , 對字符串進行匹配的正則表達式 , 對應輸出格式的正則表達式)
(650.507.9833, '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})', '(\1) \2\3' )
( [[:digit:]] {3} ) \.
子表達式開始 匹配任何數字 出現3次 子表達式結束 轉義字符'.' 第一部分
650 .
( [[:digit:]] {3} ) \.
子表達式開始 匹配任何數字 出現3次 子表達式結束 轉義字符'.' 第二部分
507 .
( [[:digit:]] {4} )
子表達式開始 匹配任何數字 出現4次 子表達式結束 第三部分
9833
( \1 ) \2 - \3
(前面匹配的第一部分) [空格] 前面匹配的第一部分 - 前面匹配的第一部分
( 650 ) 507 - 9833
A. xxx-xxx-xxxx
B. (xxx) xxxxxxx
C. (xxx) xxx-xxxx(right)
'(\1) \2-\3'這個格式很說明問題
D. xxx-(xxx)-xxxx
22. Which statement correctly grants a system privilege?
A. GRANT EXECUTE ON proc1 TO PUBLIC
授予所有用戶執行過程proc1的權限,這是對象權限不是系統權限
B. GRANT CREATE VIEW ON table1 TO user1
create view是系統權限,沒有在某個表上的創建視圖的權限,得到create view權限和select on table對象權限就可以創建到其他用戶的表的視圖
C. GRANT CREATE TABLE TO user1,user2(right)
GRANT 權限名 TO 用戶(角色)1,用戶(角色)2
D. GRANT CREATE SESSION TO ALL
要想所有用戶授權是to public不是to all
23. View the Exhibit and examine the structure of the CUST table.
Evaluate the following SQL statements executed in the given order:
ALTER TABLE cust
ADD CONSTRAINT cust_id_pk PRIMARY KEY(cust_id) DEFERRABLE INITIALLY DEFERRED
INSERT INTO cust VALUES (1,'RAJ'); --row1
INSERT INTO cust VALUES (1,'SAM'); --row2
COMMIT;
此時PRIMARY KEY狀態DEFERRABLE INITIALLY DEFERRED,在commit是檢查約束,row1,row2一起提交,同時失敗
SET CONSTRAINT cust_id_pk IMMEDIATE;
此時PRIMARY KEY狀態DEFERRABLE INITIALLY IMMEDIATE,發出命令后立即檢查約束
INSERT INTO cust VALUES (1,'LATA'); --row3
發出命令檢查約束,執行成功
INSERT INTO cust VALUES (2,'KING'); --row4
發出命令檢查約束,執行成功
COMMIT;
提交成功
Which rows would be made permanent in the CUST table?
A. row 4 only
B. rows 2 and 4
C. rows 3 and 4(right)
D. rows 1 and 4
24. View the Exhibit and examine the structure of the ORDERS table:
The ORDER_ID column has the PRIMARY KEY constraint and CUSTOMER_ID has the NOT NULL
constraint.
Evaluate the following statement:
INSERT INTO (
SELECT order_id,order_date,customer_id
FROM ORDERS
WHERE order_total = 1000
WITH CHECK OPTION
)
VALUES (13, SYSDATE, 101)
What would be the outcome of the above INSERT statement?
語句可理解為INSERT INTO(view) values()
當view帶有WITH CHECK OPTION時,要求對視圖的操作結果也要在視圖的范圍內,即(13,sysdate,101)要符合view各列的順序並且order_total = 1000
所以(13,sysdate,101)對應order_id,order_date,customer_id導致order_total沒有賦值,插入結果也就不會落在視圖范圍,違反了WITH CHECK OPTION約束,該語句將報錯
解決該錯誤的方法有:
1. 將where條件從order_total改為order_id,order_date,customer_id三者中的一個或幾個
2. 將order_total加入view中,使得insert時對應的order_total值為1000
A. It would execute successfully and the new row would be inserted into a new temporary table created by the subquery.
本語句不會正確執行,並且即使執行了,修改的也是view所基於的表,而不是這個子查詢所創建的臨時表
B. It would execute successfully and the ORDER_TOTAL column would have the value 1000 inserted automatically in the new row.
本語句不會正確執行,並且當插入數據時某一列沒有被指定,也沒有設置默認值時,系統不會將其設為特定值而是設為null
C. It would not execute successfully because the ORDER_TOTAL column is not specified in the SELECT list and no value is provided for it.(right)
D. It would not execute successfully because all the columns from the ORDERS table should have been included in the SELECT list and values should have been provided for all the columns.
view的WITH CHECK OPTION約束僅要求結果落在視圖范圍,並不要求視圖選擇表的全部列
25. View the Exhibit and examine the description of the EMPLOYEES table.
Your company wants to give 5% bonus to all the employees on their annual salary(年工資增加5%). The SALARY column stores the monthly salary(月工資) for an employee. To check the total for annual salary and bonus amount for each employee, you issued the following SQL statement:
SELECT first_name, salary, salary*12+salary*12*.05 "ANNUAL SALARY + BONUS"
FROM employees
Which statement is true regarding the above query?
A. It would execute and give you the desired output.(right)
B. It would not execute because the AS keyword is missing between the column name and the alias.
as關鍵字在ansi sql中被要求輸入,pl/sql中可以輸入也可以省略
C. It would not execute because double quotation marks are used instead of single quotation marks for assigning alias for the third column.
對列起別名時是使用雙引號來修飾而不是單引號
D. It would execute but the result for the third column would be inaccurate(不准確的) because the parentheses(括號) for overriding the precedence of the operator are missing
翻譯: 它能否被執行,但是第三列的結果將不准確,因為為了重寫優先級的運算符的括號沒有了
解釋: x*1.05=x+x*0.05,顯然不用括號調整優先級
26. Which statement is true regarding external tables?
A. The default REJECT LIMIT for external tables is UNLIMITED.
翻譯: 外部表的REJECT LIMIT默認值為UNLIMITED
解釋: 外部表的默認的REJECT LIMIT值為0
B. The data and metadata for an external table are stored outside the database.
翻譯: 外部表的數據和元數據儲存在數據庫之外.
解釋: 外部表的數據的確儲存在數據庫之外,但是外部表的元數據儲存在數據字典中才使得你可以訪問外部表
C. ORACLE_LOADER and ORACLE_DATAPUMP have exactly the same functionality when used with an external table.
翻譯: ORACLE_LOADER和ORACLE_DATAPUMP有完全一樣的功能,當用於外部表的時候
解釋: ORACLE_LOADER可以加載所有數據,ORACLE_DATAPUMP只能加載oracle特定的2進制文件*.dmp
D. The CREATE TABLE AS SELECT statement can be used to unload data into regular table in the database from an external table(right)
翻譯: CREATE TABLE AS SELECT語句可以用來將外部表的數據卸載到數據庫中正常的表里
解釋: CREATE TABLE...ORGANIZATION EXTERNAL用來定義外部表,CREATE TABLE AS SELECT則將定義的外部表的數據裝載到數據庫內部的表,這樣就可以對表進行insert,update,delete了
27. View the Exhibit and examine the structure of the PRODUCT_INFORMATION table.
You want to see the product names and the date of expiration(到期) of warranty(保修) for all the products, if the product is purchased(購買) today.
你想看product names和所有產品的保修到期日,假設產品是今天購買的.
The products that have no warranty should be displayed at the top and the products with maximum warranty period should be displayed at the bottom.
沒有保修的產品要顯示在頂端,保修期最大的產品顯示在底端.
product_information表warranty_period(保修期)列類型為interval year(2)tomonth
INTERVAL數據類型用來存儲兩個時間戳之間的時間間隔。可以指定years and months等
INTERVAL '10-2' YEAR(2) TO MONTH意思是10年2個月
本題考點就是排序
要求沒有保修的產品要顯示在頂端,保修期最大的產品顯示在底端.
就是以warranty_period進行升序排序,sysdate都是一樣的,所以warranty_period+sysdate也可以
Which SQL statement would you execute to fulfill this requirement?
A. SELECT product_name, category_id, SYSDATE+warranty_period AS "Warranty expire date"
FROM product_information
ORDER BY SYSDATE-warranty_period
解釋:應該按warranty_period升序排序,如果是按SYSDATE-warranty_period的話,要降序排序,使用desc后綴
B. SELECT product_name, category_id, SYSDATE+warranty_period AS "Warranty expire date"
FROM product_information
ORDER BY SYSDATE+warranty_period
right
C. SELECT product_name, category_id, SYSDATE+warranty_period AS "Warranty expire date"
FROM product_information
ORDER BY SYSDATE
解釋: SYSDATE是一致的,所以以SYSDATE排序沒有任何意義
D. SELECT product_name, category_id, SYSDATE+warranty_period "Warranty expire date"
FROM product_information
WHERE warranty_period >SYSDATE?
解釋:SYSDATE是當前時間戳,warranty_period是時間跨度,比較大小沒有意義
28. Which two statements are true regarding the EXISTS operator used in the correlated subqueries?
(Choose two.)
A. The outer query stops evaluating the result set of the inner query when the first value is found.(right)
翻譯: 外查詢停止評估內查詢的結果集,當第一個值被發現
B. It is used to test whether the values retrieved by the inner query exist in the result of the outer query.
翻譯: 他被用以試驗被內查詢檢索的值是否在外查詢的結果集中存在
C. It is used to test whether the values retrieved by the outer query exist in the result set of the inner query.(right)
翻譯: 他被用以試驗被外查詢檢索的值是否在內查詢的結果集中存在
D. The outer query continues evaluating the result set of the inner query until all the values in the result
翻譯: 外查詢繼續評估內查詢的結果集,直到評估完結果中全部的值
舉例:
select id, name,salary
from employees
where exists (
select id
from employees
where id in (1,2,3)'
)
當內查詢select id from employees where id in (1,2,3)搜索不到id為1或者2或者3的記錄時,內查詢返回false到外查詢
當內查詢select id from employees where id in (1,2,3)搜索到第一個id為1或者2或者3的記錄時,內查詢直接彈回true外查詢
所以稱exists為半查詢
29. A noncorrelated(不相關的) subquery(子查詢)can be defined()定義 as ____.
A. a set of sequential queries, all of which must always return a single value
翻譯: 一個由連續的查詢組成的集合,所有的查詢必須總是返回一個值。
解釋: 如果外部查詢時in關鍵字,返回多個值也是可以的。
B. a set of sequential queries, all of which must return values from the same table
翻譯: 一個連續的查詢集,所有的查詢必須返回來自同一個表的值。
解釋: 不要求查詢的結果來自同一個表
C. a SELECT statement that can be embedded in a clause of another SELECT statement only
翻譯: 一個select語句,只能被嵌入另一個條件的select語句
解釋: 一個select語句嵌套在另一個select語句就是嵌套查詢,兩條語句條件一樣無非就是一個語句執行兩次而已
D. a set of one or more sequential queries in which generally the result of the inner query is used as the search value in the outer query.(right)
翻譯: 一個由一個或多個連續的查詢組成的集合,通常內查詢的結果被用來作為外查詢搜索的值。
本題用排除法,A,B,C都有錯誤所以選D,實際上對於Correlated Subqueries和Noncorrelated Subqueries來說D都是正確的,因為D只是解釋了Subquery。
30. You need to create a table for a banking(金融) application(應用) with the following considerations(注意事項):
1) You want a column in the table to store the duration(持續時間) of the credit(貸款) period(時期).
你希望表中的一列儲存貸款期的持續時間(這是一個時間的跨度)
2) The data in the column should be stored in a format such that it can be easily added and subtracted with
列中的數據要以容易做加減的形式保存
3) date type data without using the conversion functions.
日期類型的數據不使用轉換函數
4) The maximum period of the credit provision in the application is 30 days.
程序中提供的貸款最大期限為30天(時間跨度不超過30天,year to month太大,要使用day to second)
5) The interest has to be calculated for the number of days an individual has taken a credit for.
要計算個人獲得貸款的天數的利息
Which data type would you use for such a column in the table?
A. INTERVAL YEAR TO MONTH
時間跨度太大,題目要求不超過30天
B. INTERVAL DAY TO SECOND(right)
C. TIMESTAMP WITH TIME ZONE
TIMESTAMP是時間c戳,不是時間跨度
D. TIMESTAMP WITH LOCAL TIME ZONE
TIMESTAMP是時間c戳,不是時間跨度
31. Which statements are true regarding the hierarchical query(級聯查詢) in Oracle Database 10g? (Choose all that apply.)
A. It is possible to retrieve data only in topdown hierarchy.
翻譯: 可以檢索top-down結構(由根到葉)的數據
解釋: 級聯查詢可以查詢top-down結構和bottom-up結構的數據。PRIOR關鍵詞用來指定誰是父記錄誰是子記錄。
B. It is possible to retrieve data in topdown or bottomup hierarchy.(right)
翻譯: 可以檢索top-down結構(由根到葉)或者bottom-up結構(即由葉到根)的數據
C. It is possible to remove an entire branch from the output of the hierarchical query.(right)
翻譯: 可以從級聯查詢德輸出結果中移除整個分支
解釋: 並不是刪除整個分支,而是在級聯查詢中去除,選擇性的顯示所需要的分支信息,可以通過指定不同的root或者父記錄與子記錄間的關系
D. You cannot specify conditions when you retrieve data by using a hierarchical query
翻譯: 你用級聯查詢檢索數據時不能指定條件
解釋: 級聯查詢用START WITH指定根的條件,用CONNECT BY指定父記錄與子記錄之間的關系.
32. Which two statements are true regarding views? (Choose two.)
A. A simple view in which column aliases have been used cannot be updated
翻譯: 一張列的別名被使用的簡單視圖不能進行修改
解釋: 如果是簡單視圖的話,可以進行update操作,不管列是不是取了別名。
B. A subquery used in a complex view definition cannot contain group functions or joins.
翻譯: 在一個復雜的視圖定義下使用的子查詢不能包含聚合函數或者連接
解釋: 就是因為使用了聚合函數或者連接,所以才成為復雜的視圖。所以子查詢必須可以包含聚合函數或者連接
C. Rows cannot be deleted through a view if the view definition contains the DISTINCT keyword.(right)
翻譯: 如果視圖定義包含了DISTINCT關鍵字,那么不能通過這個視圖刪除行。
解釋: 在包含DISTINCT關鍵字的視圖上不允許DML操作。
D. Rows added through a view are deleted from the table automatically when the view is dropped.
翻譯: 當視圖被刪除時,通過視圖添加的行將自動的從表中被刪除。
解釋: 通過視圖添加的行實際上是添加在視圖所指向的表上,所以刪除視圖對視圖基於的表沒有任何關聯操作。
E. The OR REPLACE option is used to change the definition of an existing view without dropping and recreating it.(right)
翻譯: OR REPLACE選項使用來改變一個已經存在的視圖的定義,不用刪除視圖再重新創建它。
F. The WITH CHECK OPTION constraint can be used in a view definition to restrict the columns displayed through the view.
翻譯: WITH CHECK OPTION約束可以被使用來在一個視圖定義中限制通過視圖顯示的列。
解釋: WITH CHECK OPTION約束是限制dml操作結果必須落在視圖范圍,而確定視圖顯示的列則是在創建視圖時指定的。
33. View the Exhibit and examine the details of the ORDER_ITEMS table.
Evaluate the following SQL statements:
Statement 1:
SELECT MAX(unit_price*quantity) "Maximum Order"
FROM order_items
對所有的行計算unit_price*quantity,輸出最大值(1行)
Statement 2:
SELECT MAX(unit_price*quantity) "Maximum Order"
FROM order_items
GROUP BY order_id
以order_id分組,計算unit_price*quantity,輸出各組最大值(3行)
Which statements are true regarding the output of these SQL statements? (Choose all that apply.)
A. Statement 1 would return only one row of output.(right)
B. Both the statements would give the same output.
翻譯: 2個語句給出相同的輸出
解釋: 語句1有1行輸出,語句2有3行輸出,不相同。
C. Statement 2 would return multiple rows of output.(right)
D. Statement 1 would not return any row because the GROUP BY clause is missing.
翻譯: 語句1不會返回任何行因為缺少GROUP BY條件
解釋: 沒有GROUP BY條件會計算unit_price*quantity,輸出所有行之中的最大值,所以有1行輸出
E. Both statements would ignore NULL values for the UNIT_PRICE and QUANTITY columns.(right)
34. View the Exhibit and examine the structure of the ORDERS and ORDER_ITEMS tables.
Evaluate the following SQL statement:
SELECT oi.order_id, product_id, order_date
FROM order_items oi JOIN orders o
USING(order_id)
Which statement is true regarding the execution of this SQL statement?
A. The statement would not execute because table aliases are not allowed in the JOIN clause.
翻譯: 語句不會被執行,因為join條件中不允許使用表的別名
解釋: 對表起別名就是在join語句中指定的。
B. The statement would not execute because the table alias prefix is not used in the USING clause.
翻譯: 語句不會被執行,因為表的別名前綴沒有在using條件中被使用
解釋: using條件是不能用表的別名修飾列名的,只有on條件要用表的別名修飾。
C. The statement would not execute because all the columns in the SELECT clause are not prefixed with table aliases.
翻譯: 語句不會被執行,因為select條件中所有的列沒有表的別名作為前綴
解釋: 只有多個表的同名列需要用[表名.列名]來唯一確定。
D. The statement would not execute because the column part of the USING clause cannot have a qualifier in the SELECT list.(right)
翻譯: 語句不會被執行,因為using條件的列部分不能在select列表中有限定詞
35. Evaluate the following SQL statements in the given order:
DROP TABLE dept
CREATE TABLE dept(
deptno NUMBER(3) PRIMARY KEY,
deptname VARCHAR2(10)
)
DROP TABLE dept
FLASHBACK TABLE dept TO BEFORE DROP
閃回表遵從同名表后進先出原則
對表使用閃回要求該表的行移動為允許
alter table binzhang ENABLE ROW MOVEMENT
Which statement is true regarding the above FLASHBACK operation?
A. It recovers only the first DEPT table.
同名表后進先出原則,恢復第2個表
B. It recovers only the second DEPT table.(right)
C. It does not recover any of the tables because FLASHBACK is not possible in this case.
刪除表示僅用drop是可以使用flashback恢復的,用truncate table或者purge table無法恢復,
D. It recovers both the tables but the names would be changed to the ones assigned in the RECYCLEBIN.
閃回一次恢復一個,同名表閃回要rename to新表名
FLASHBACK TABLE [ schema. ]table [, [ schema. ]table ]... TO { { SCN | TIMESTAMP } expr [ { ENABLE | DISABLE } TRIGGERS ] | BEFORE DROP [ RENAME TO table ] } ;
flashback table test_purge to before drop;
flashback table test_purge to before drop rename to test_purge_old;
flashback table test_purge to SCN | TIMESTAMP
36. Evaluate the following statements:
CREATE TABLE digits(
id NUMBER(2),
description VARCHAR2(15)
)
創建digits表
INSERT INTO digits VALUES (1,'ONE')
插入(1,'ONE')
UPDATE digits SET description ='TWO' WHERE id=1
將(1,'ONE')改為(1,'two')
INSERT INTO digits VALUES (2,'TWO')
插入(2,'TWO')
COMMIT
digits表中記錄為(1,'two'),(2,'TWO'),只有commit以后閃回版本查詢才能查詢到版本的更新
DELETE FROM digits
刪除2行,但是沒有commit,如果commit閃回版本查詢比原來就會多出2行"TWO"
SELECT description FROM digits
VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE
閃回版本查詢會記錄每次commit后各版本的差異,不提交沒記錄
What would be the outcome of the above query?
A. It would not display any values.
B. It would display the value TWO once.
C. It would display the value TWO twice.(right)
D. It would display the values ONE, TWO, and TWO.
37. View the Exhibit and examine the description of the ORDERS table.
Evaluate the following SQL statement:
SELECT order_id, customer_id
FROM orders
WHERE order_date > 'June 30 2001'
order_date是timestamp類型,'June 30 2001'是字符串.
Oracle不會自動轉換,要顯式調用to_date()或者to_char()
Which statement is true regarding the execution of this SQL statement?
A. It would not execute because 'June 30 2001' in the WHERE condition is not enclosed within double quotation marks.
翻譯: 它將不會執行因為在where條件中的'June 30 2001'沒有被雙引號封閉
解釋: sql里的字符串時用單引號修飾
B. It would execute and would return ORDER_ID and CUSTOMER_ID for all records having ORDER_DATE greater than 'June 30 2001'.
翻譯: 他將執行並返回所有ORDER_DATE大於'June 30 2001'的記錄的ORDER_ID和CUSTOMER_ID
解釋: 本語句執行會報錯,因為日期和字符串oracle不會隱式轉換
C. It would not execute because 'June 30 2001' in the WHERE condition cannot be converted implicitly and needs the use of the TO_DATE conversion function for proper execution.(right)
翻譯: 它將不會執行因為在where條件中的'June 30 2001'不能隱式轉換並且需要使用TO_DATE轉換函數恰當的執行
D. It would not execute because 'June 30 2001' in the WHERE condition cannot be converted implicitly and needs the use of the TO_CHAR conversion function for proper execution.
翻譯: 它將不會執行因為在where條件中的'June 30 2001'不能隱式轉換並且需要使用TO_CHAR轉換函數恰當的執行
解釋: 'June 30 2001'是字符串,對其使用to_char()是沒有意義的,應該使用to_date(),也不能對order_date使用to_char(),因為字符串作比較是比ascii碼,不會比英語單詞意思的
38. Which statements are correct regarding indexes? (Choose all that apply.)
A. When a table is dropped, the corresponding indexes are automatically dropped.(right)
翻譯: 當表被刪除時,對應的索引也自動被刪除.
B. For each DML operation performed, the corresponding indexes are automatically updated.(right)
翻譯: 每條DML操作執行,對應的索引都會自動更新
C. Indexes should be created on columns that are frequently referenced as part of an expression.
翻譯: 索引必須創建在頻繁的作為表達式的一部份被引用的列上
解釋: 建議為頻繁使用的列建立索引,但是這不是強制性的,頻繁使用的列可以不建索引,索引可以建在任何列上
D. A nondeferrable PRIMARY KEY or UNIQUE KEY constraint in a table automatically creates a unique index.(right)
翻譯: 一個表中的一個不可延時的主鍵或者唯一鍵約束會自動建立一個唯一索引
39. View the Exhibit and examine the description of the PRODUCT_INFORMATION table.
Which SQL statement would retrieve(檢索) from the table the number of products having LIST_PRICE as NULL?
比較null值用is NULL,任何NULL不等於其他NULL,使用count(列名)會忽略列中值為NULL的行,count(*)返回記錄數,NULL也算一條記錄
A. SELECT COUNT(list_price)
FROM product_information
WHERE list_price IS NULL
解釋: COUNT(list_price)返回list_price不為NULL的個數
B. SELECT COUNT(list_price)
FROM product_information
WHERE list_price = NULL
解釋: 值為NULL寫作is NULL,不可寫為= NULL
C. SELECT COUNT(NVL(list_price, 0))(right)
FROM product_information
WHERE list_price IS NULL
解釋: nvl(arg,value)代表如果前面的arg的值為null那么返回的值為后面的value
D. SELECT COUNT(DISTINCT list_price)
FROM product_information
WHERE list_price IS NULL
解釋: DISTINCT是去除重復的關鍵字,不管有沒有DISTINCT關鍵字,count()都返回不是null的個數,
40. User OE, the owner of the ORDERS table, issues the following command:
GRANT SELECT,INSERT ON orders TO hr WITH GRANT OPTION
授予hr對表orders的SELECT,INSERT權限,並且授予hr將這些權限授予別人的權限
The user HR issues the following command:
GRANT SELECT ON oe.orders TO scott
授予scott對表oe.orders的SELECT權限
Then, OE issues the following command:
REVOKE ALL ON orders FROM hr
撤銷hr對表orders的所有權限
WITH GRANT OPTION只能在賦予 object privilege 的時使用,撤銷時有連帶效果oe>>hr>>scott
Which statement is correct?
A. The user SCOTT loses the privilege to select rows from OE.ORDERS.(right)
B. The user SCOTT retains the privilege to select rows from OE.ORDERS.
翻譯: SCOTT保留了對OE.ORDERS表的select權限
解釋: 對象權限撤銷時會連帶撤銷通過WITH GRANT OPTION傳遞的權限
C. The REVOKE statement generates an error because OE has to first revoke the SELECT privilege from SCOTT.
翻譯: 撤銷語句產生一個錯誤,因為OE要先撤銷scott的select權限
解釋: 撤銷任何權限時都不會要求先撤銷其他通過WITH ADMIN/GRANT OPTION獲得權限的用戶/角色
D. The REVOKE statement generates an error because the ALL keyword cannot be used for privileges
翻譯: 撤銷語句產生一個錯誤,因為關鍵詞ALL不能用於權限
解釋: GRANT ALL PRIVILEGES TO user/role/public [IDENTIFIED BY password] [WITH ADMIN OPTION]
GRANT ALL PRIVILEGES ON [schema.]object TO user/role/public [WITH GRANT OPTION] [WITH HIERARCHY OPTION]
41. View the Exhibit and examine the structure of the EMP table.
You executed the following command to add a primary key to the EMP table:
ALTER TABLE emp ADD CONSTRAINT emp_id_pk PRIMARY KEY (emp_id)
USING INDEX emp_id_idx.
Which statement is true regarding the effect of the command?
A. The PRIMARY KEY is created along with a new index.
B. The PRIMARY KEY is created and it would use an existing unique index.
C. The PRIMARY KEY would be created in a disabled state because it is using
an existing index.
D. The statement produces an error because the USING clause is permitted only
in the CREATE TABLE
command.
Answer: B
The USING INDEX clause only works for PRIMARY KEY and UNIQUE constraints.
It can be appended to any PRIMARY KEY or UNIQUE constraint specification.
including the in-line anonymous, in-line named, and out-of-line syntax.
The USING INDEX clause for creating indices can be used to specify an
existing index by appending a constraint specification with “USING INDEX
index_name” and nothing else.
42. SCOTT is a user in the database.
Evaluate the commands issued by the DBA:
1 -CREATE ROLE mgr.
2 -GRANT CREATE TABLE, SELECT ON oe.orders TO mgr.
3 -GRANT mgr, create table TO SCOTT.
Which statement is true regarding the execution of the above commands?
A. Statement 1 would not execute because the WITH GRANT option is missing.
B. Statement 1 would not execute because the IDENTIFIED BY <password> clause
is missing.
C. Statement 3 would not execute because role and system privileges cannot
be granted together in a single GRANT statement.
D. Statement 2 would not execute because system privileges and object
privileges cannot be granted together in a single GRANT command.
Answer: D
43. Which statement best describes the GROUPING function?
A. It is used to set the order for the groups to be used for calculating the
grand totals and subtotals.
B. It is used to form various groups to calculate total and subtotals created
using ROLLUP and CUBE operators.
C. It is used to identify if the NULL value in an expression is a stored NULL
value or created by ROLLUP or CUBE.
D. It is used to specify the concatenated group expressions to be used for
calculating the grand totals and subtotals.
Answer: C
The GROUPING function identifies superaggregate or aggregate rows produced by
a ROLLUP or CUBE operation in a SELECT . . . GROUP BY statement. It returns a value
of the NUMBER datatype, and its value is either a one (1) or a zero (0).The GROUPING
function is only valid in a SELECT statement that uses a GROUP BY clause. While GROUPING
may be used in a GROUP BY that doesn’t include the ROLLUP or CUBE operation, it doesn’t
produce anything meaningful without those operators—it will always return a zero if
ROLLUP and CUBE are absent from the statement.
SQL> select grouping(division_id),division_id,sum(salary)
from employees2
group by rollup(division_id)
order by division_id;
GROUPING(DIVISION_ID) DIV SUM(SALARY)
--------------------- --- -----------
0 BUS 1610000
0 OPE 1320000
0 SAL 4936000
0 SUP 1015000
1 8881000
可以看到,為空的地方返回1,非空的地方返回0。
44. View the Exhibit and examine the structure of ORD and ORD_ITEMS tables.
In the ORD table, the PRIMARY KEY is ORD_NO and in the ORD_ITEMS tables the
composite
PRIMARY KEY is (ORD_NO, ITEM_NO).
Which two CREATE INDEX statements are valid? (Choose two.)
A. CREATE INDEX ord_idx
ON ord(ord_no);
B. CREATE INDEX ord_idx
ON ord_items(ord_no);
C. CREATE INDEX ord_idx
ON ord_items(item_no);
D. CREATE INDEX ord_idx
ON ord,ord_items(ord_no, ord_date,qty);
Answer: BC
建立主鍵的時候會自動在其上建立唯一索引
SQL> create table temp(a int not null primary key,b int,c int);
SQL> create index temp_ind on temp(a);
ORA-01408: 此列列表已索引
45. View the Exhibit and examine the structure of the CUSTOMERS table.
CUSTOMER_VU is a view based on CUSTOMERS_BR1 table which has the same
structure as CUSTOMERS table. CUSTOMERS needs to be updated to reflect the
latest information about the customers.
What is the error in the following MERGE statement?
MERGE INTO customers c
USING customer_vu cv
ON (c.customer_id = cv.customer_id)
WHEN MATCHED THEN
UPDATE SET
c.customer_id = cv.customer_id,
c.cust_name = cv.cust_name,
c.cust_email = cv.cust_email,
c.income_level = cv.income_level
WHEN NOT MATCHED THEN
INSERT VALUES(cv.customer_id,cv.cust_name,cv.cust_email,cv,income_level)
WHERE cv.income_level >’100000’;
A. The CUSTOMER_ID column cannot be updated.
B. The INTO clause is misplaced in the command.
C. The WHERE clause cannot be used with INSERT.
D. CUSTOMER_VU cannot be used as a data source.
Answer: A
Reflect:反映
46. Which two statements are true regarding operators used with subqueries?
(Choose two.)
A. The NOT IN operator is equivalent to IS NULL.
B. The <ANY operator means less than the maximum.
C. =ANY and =ALL operators have the same functionality.
D. The IN operator cannot be used in singlerow subqueries.
E. The NOT operator can be used with IN, ANY and ALL operators.
Answer: BE
Equivalent:相當 functionality:功能
其實就是把NOT放到整個表達式之前:如果是NOT ANY, NOT ALL是行不通的。
WHERE NOT col IN (SELECT ...)
WHERE NOT col = ANY (SELECT ...)
WHERE NOT col = ALL (SELECT ...)
找出員工中,只要比部門號為10的員工中的任何一個員工的工資高的員工的姓名個工資。
也就是說只要比部門號為10的員工中的那個工資最少的員工的工資高就滿足條件。
select ename,sal From emp Where sal > any(select sal from emp where deptno = 10);
下面的SQL語句的意義與前面的就完全不一樣了,其意義是找到比部門號為20的員工的所有
員工的工資都要高的員工,也就是比那個工資最高的員工的還要高的員工
select ename,sal From emp Where sal > all(select sal from emp where deptno = 20);
All:所有的
如>all則需要大於所有的,<all則需小於所有的
Any:任何一個
如>any則需要大於其中任何一個,<any則小於其中任何一個。
對應any, 小於對應最大值,大於對應最小值
<ANY means less than the maximum. >ANY means more than the minimum. =ANY is
equivalent to IN.
對應all, 小於對應最小值,大於對應最大值(sg有誤)
<ALL means less than the minimum. >ALL means more than the maximum.
另外關於子查詢的結論:
-- 子查詢中有空值,其結果也返回空值
-- 子查詢中不能使用order by
-- null是個不容易對付的家伙,問下面SQL的返回值是多少?
select case when null=null then 'ok' else 'err' end from dual; 答案: err
select case when null is null then 'ok' else 'err' end from dual; 答案: ok
-- WHERE 子句中的子查詢可以嵌套的層數是255
-- 在關聯子查詢中,內部查詢對外部查詢處理的每一行執行一次
47. Given below are the SQL statements executed in a user session:
CREATE TABLE product
(pcode NUMBER(2),
pname VARCHAR2(10));
INSERT INTO product VALUES(1, 'pen');
INSERT INTO product VALUES (2,'pencil');
SAVEPOINT a;
UPDATE product SET pcode = 10 WHERE pcode = 1;
SAVEPOINT b;
DELETE FROM product WHERE pcode = 2;
COMMIT;
DELETE FROM product WHERE pcode=10;
ROLLBACK TO SAVEPOINT a;
Which statement describes the consequences?
A. No SQL statement would be rolled back
B. Both the DELETE statements would be rolled back.
C. Only the second DELETE statement would be rolled back.
D. Both the DELETE statements and the UPDATE statement would be rolled back.
Answer: A
試驗證明在 ROLLBACK TO SAVEPOINT前不能有COMMIT命令,否則報錯: ORA-01086:
從未創建保存點 'A'
要仔細看題
48. Evaluate the following CREATE TABLE command:
CREATE TABLE order_item
(order_id NUMBER(3),item_id NUMBER(2),qty NUMBER(4),
CONSTRAINT ord_itm_id_pk PRIMARY KEY (order_id,item_id)
USING INDEX
(CREATE INDEX ord_itm_idx ON order_item(order_id,item_id)));
Which statement is true regarding the above SQL statement?
A. It would execute successfully and only ORD_ITM_IDX index would be created.
B. It would give an error because the USING INDEX clause cannot be used on
a composite primary key.
C. It would execute successfully and two indexes ORD_ITM_IDX and
ORD_ITM_ID_PK would be
created.
D. It would give an error because the USING INDEX clause is not permitted
in the CREATE TABLE
command.
Answer: A
指定了索引創建的話,建主鍵不會再自動建索引
49. View the Exhibit and examine the description of EMPLOYEES and DEPARTMENTS
tables.You want to display the EMPLOYEE_ID, LAST_NAME, and SALARY for the
employees who get the maximum salary in their respective departments. The
following SQL statement was written:
WITH
SELECT employee_id, last_name, salary
FROM employees
WHERE (department_id, salary) = ANY (SELECT * FROM dept_max)
dept_max as ( SELECT d.department_id, max(salary)
FROM departments d JOIN employees j
ON (d.department_id = j.department_id)
GROUP BY d.department_id);
Which statement is true regarding the execution and the output of this
statement?
A. The statement would execute and give the desired results.
B. The statement would not execute because the = ANY comparison operator is
used instead of =.
C. The statement would not execute because the main query block uses the query
name before it is even created.
D. The statement would not execute because the comma is missing between the
main query block and the query name.
Answer: C
50. View the Exhibit and examine the data in the DEPARTMENTS tables.
Evaluate the following SQL statement:
SELECT department_id "DEPT_ID", department_name , 'b'
FROM departments WHERE department_id=90
UNION
SELECT department_id, department_name DEPT_NAME, 'a'
FROM departments WHERE department_id=10
Which two ORDER BY clauses can be used to sort the output of the above
statement? (Choose two.)
A. ORDER BY 3;
B. ORDER BY 'b';
C. ORDER BY DEPT_ID;
D. ORDER BY DEPT_NAME;
Answer: AC
Eg:
1: select pcode "tt",pname,'b' from product
union
select pcode ,pname ee,'a' from product
order by 'b';
ORA-01785: ORDER BY 項必須是 SELECT-list 表達式的數目
2: select pcode "tt",pname,'b' from product
union
select pcode ,pname ee,'a' from product
order by ee;
ORA-00904: "EE": 標識符無效
3: select pcode "tt",pname,'b' from product
union
select pcode ,pname ee,'a' from product
order by "tt"; ok的
51. View the Exhibit and examine the description of the EMPLOYEES table.
You want to know the EMPLOYEE_ID and FIRST_NAME of all the records in the EMPLOYEES table
wherein the JOB_ID column has ST_CLERK or ST_MAN values,
在JOB_ID列里有ST_CLERK或ST_MAN的值
the DEPARTMENT_ID column has value 30,
DEPARTMENT_ID =30
and the SALARY column has a value greater than 3,000.
SALARY>3000
Which SQL statement would get you the desired result?
題目的要求是:
(like '%CLERK' or like '%MAN')and DEPARTMENT_ID =30 and SALARY>3000
( a or b )and c and d
==>(a and c and d)or (b and c and d)
A. SELECT employee_id, first_name
FROM employees
WHERE job_id like 'MAN%' OR job_id like 'CLERK%'
AND department_id = 30 AND salary > 3000
邏輯正確,要求含有ST_CLERK,ST_MAN,通配符為%CLERK,%MAN
B. SELECT employee_id, first_name
FROM employees
WHERE job_id like '%MAN' OR job_id like '%CLERK'
AND (department_id = 30 OR salary > 3000)
department_id = 30,salary > 3000其一為假,結果可以為真,與題意不符
C. SELECT employee_id, first_name
FROM employees
WHERE (job_id like '%MAN' AND job_id like '%CLERK')
AND department_id = 30 OR salary > 3000?
salary > 3000皆為假,結果可以為真,與題意不符
D. SELECT employee_id, first_name (right)
FROM employees
WHERE (job_id like '%MAN' OR job_id like '%CLERK' )
AND department_id = 30 AND salary > 3000?
52. View the Exhibit and examine the structure of the ORDERS table.
The ORDERS table belongs to the user OE. HR is another user in the database.
Evaluate the commands issued by users OE and HR in the following order:
Statement 1 by user OE: GRANT SELECT, UPDATE(customer_id, order_total) ON orders TO hr;
Statement 1 by user HR: SELECT * FROM oe.orders;
Statement 2 by user HR: UPDATE oe.orders SET order_total= 10000;
Which statement is true regarding the above commands?
A. Statement 1 by user OE would not work because the statement has to be issued by the DBA.
ORDERS的主人是oe,oe可以將該表的對象權限授予別人
B. Statement 2 by user HR would not work because the grant is only for SELECT in a subquery of update.
Oracle的新特性可以將表中某幾列的對象權限授予別人,oe授予hr對customer_id, order_total兩列的update權限
C. There are no errors in the statements issued by OE and HR, all the statements would execute successfully. (right)
D. Statement 1 by user HR would not work because SELECT and UPDATE privileges have been granted only on CUSTOMER_ID and ORDER_TOTAL columns.
的確UPDATE權限只給了CUSTOMER_ID和ORDER_TOTAL兩列,但是select權限是給了全表的
53. View the Exhibit and examine the structure of the ORDER_ITEMS table.
You need to display the ORDER_ID of the order that has the highest total value among all the orders in
the ORDER_ITEMS table.
Which query would produce the desired output?
正確答案是:
select order_id
from order_items
group by order_id
having sum(unit_price*quantity)=(
select max(sum(unit_price*quantity))
from order_items
group by order_id
)
A. SELECT order_id
FROM order_items
WHERE(unit_price*quantity) = MAX(unit_price*quantity)
GROUP BY order_id
max()聚合函數不能用於where條件
B. SELECT order_id
FROM order_items
WHERE(unit_price*quantity) = (SELECT MAX(unit_price*quantity)
FROM order_items)
GROUP BY order_id
一個order_id有多行記錄,(SELECT MAX(unit_price*quantity) FROM order_items)只能找到一行的最大值,結果沒有實際意義
C. SELECT order_id
FROM order_items
WHERE (unit_price*quantity) = (SELECT MAX(unit_price*quantity)
FROM order_items
GROUP BY order_id)
子查詢返回的是GROUP BY order_id以后最大的單行unit_price*quantity,與題意不符
D. SELECT order_id (right)
FROM order_items
GROUP BY order_id
HAVING SUM(unit_price*quantity) =(SELECT MAX(SUM(unit_price*quantity))
FROM order_items GROUP BY order_id)
54. Which two statements are true about sequences created in a single instance database? (Choose two.)
A. The numbers generated by a sequence can be used only for one table.
翻譯: 序列產生的數字只能被用於一個表
解釋: 可以用於幾個標,序列不是基於表建立的。
B. DELETE <sequencename> would remove a sequence from the database.
解釋: 刪除序列用drop sequence sequence_name
C. CURRVAL is used to refer to the last sequence number that has been generated. (right)
翻譯: CURRVAL用來提交序列最后產生的數字
D. When the MAXVALUE limit for a sequence is reached, you can increase the MAXVALUE limit by using the ALTER SEQUENCE statement. (right)
翻譯: 當序列達到最大值限制時,你可以通過alter sequence語句來增加最大值限制
E. When a database instance shuts down abnormally, the sequence numbers that have been cached but not used would be available once again when the database instance is restarted.
翻譯: 當數據庫實例非正常關閉,進入緩存但是沒有使用的序列數字可以在數據庫實例重新啟動后再次有效。
解釋: 數據庫非正常關閉會丟失已經讀入緩存的序列數字,這些數字將永遠丟失
序列的最大值、最小值,步進都是可以通過alter sequence更改的,但是序列的當前值不能用alter sequence更改,要多次調用sequence.netvalue來改變
55. View the Exhibit and examine the structure of the EMPLOYEES and DEPARTMENTS tables.
Which SET operator would you use in the blank space in the following SQL statement to list the
departments where all the employees have managers?
要求顯示所有的雇員有經理的部門
SELECT department_id FROM departments 返回的是所有的部門
SELECT department_id FROM employees WHERE manager_id IS NULL?返回的是所有沒有經理的部門
所以2個集合的差集就是所有有經理的部門
SELECT department_id
FROM departments
____
SELECT department_id
FROM employees
WHERE manager_id IS NULL?
A. UNION
交集並且去除重復記錄
B. MINUS (right)
差集
C. INTERSECT
並集
D. UNION ALL
交集不去除重復記錄
56. Which mandatory(強制性的) clause has to be added to the following statement to successfully create an external table called EMPDET?
CREATE TABLE empdet (
empno CHAR(2),
ename CHAR(5),
deptno NUMBER(4)
)
ORGANIZATION EXTERNAL (
LOCATION ('emp.dat')
);
A. TYPE
type 數據轉換驅動器,oracle_loader為默認,也可以改換其他如databump
B. REJECT LIMIT
REJECT LIMIT遇到錯誤退出,0為默認值,可以指定值或使用unlimited
C. DEFAULT DIRECTORY (right)
DEFAULT DIRECTORY工作目錄,必須顯式指定外部表的目錄路徑,不設定工作目錄是無法創建外部表的
D. ACCESS PARAMETERS
轉換參數,如列分割符,錯誤的設置不會妨礙對外部表的創建,但是訪問外部表時會出錯
舉例:
CREATE TABLE "USERLIST" (
ID NUMBER,
USERNAME VARCHAR2(30),
EMAIL VARCHAR2(128)
)
ORGANIZATION external (
TYPE oracle_loader
DEFAULT DIRECTORY TEMP
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'TEMP':'userlist.bad'
DISCARDFILE 'TEMP':'userlist.dis'
LOGFILE 'TEMP':'user.log'
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
)
location (
'userlist.txt'
)
)
REJECT LIMIT UNLIMITED
57. View the Exhibit and examine the description of the ORDER_ITEMS and PRODUCT_INFORMATION tables.
The ORDER_ITEM table has records pertaining to details for each product in an order.
The PRODUCT_INFORMATION table has records for all the products available for ordering.
Evaluate the following SQL statement:
SELECT oi.order_id, pi.product_id
FROM order_items oi RIGHT OUTER JOIN product_information pi
ON (oi.product_id=pi.product_id);
右外連接,顯示product_information表的所有記錄和能夠和product_information 連接的order_items 表記錄
Which statement is true regarding the output of this SQL statement?
A. The query would return the ORDER_ID and PRODUCT_ID for only those products that are ordered.
翻譯: 查詢返回那些被訂購的產品的ORDER_ID和PRODUCT_ID
解釋: 應該返回所有PRODUCT_ID和被訂購的ORDER_ID
B. The query would return the ORDER_ID and PRODUCT_ID for the products that are ordered as well as for the products that have never been ordered.(right)
翻譯: 查詢返回那些被訂購和沒有被訂購的產品的ORDER_ID和PRODUCT_ID
C. The query would return the ORDER_ID and PRODUCT_ID for the products that are ordered but not listed in the PRODUCT_INFORMATION table.
翻譯: 查詢返回那些被訂購的但是沒有在PRODUCT_INFORMATION表中列出的產品的ORDER_ID和PRODUCT_ID
解釋: 這個是左外連接的含義,題目是右外連接
D. The query would return the ORDER_ID and PRODUCT_ID for those products that are ordered as well as for the products that have never been ordered, and for the products that are not listed in the PRODUCT_INFORMATION table.
翻譯: 查詢返回那些被訂購和沒有被訂購的產品,還有沒有在PRODUCT_INFORMATION表中列出的產品的ORDER_ID和PRODUCT_ID
解釋: 這個是全外連接的含義,題目是右外連接
58. Evaluate the following statement:
CREATE TABLE bonuses(
employee_id NUMBER,
bonus NUMBER DEFAULT 100
);
The details of all employees who have made sales need to be inserted into the BONUSES table.
有銷售的雇員的詳細情況需要插入BONUSES表。
You can obtain the list of employees who have made sales based on the SALES_REP_ID column of the ORDERS table.
你可以用過ORDERS表的SALES_REP_ID列獲得有銷售的雇員的列表。
The human resources manager now decides that employees with a salary of $8,000 or less should receive a bonus.
人力資源經理現在決定有8000美元或以下工資的雇員將得到獎勵
Those who have not made sales get a bonus of 1% of their salary.
那些沒有銷售的人獲得他們工資1%的獎勵
Those who have made sales get a bonus of 1% of their salary and also a salary increase of 1%.
那些有銷售的人獲得他們工資1%的獎勵並且工資增加1%
The salary of each employee can be obtained from the EMPLOYEES table.
每個雇員的工資可以在EMPLOYEES表獲得。
本題要求向bonuses表插入雇員工資1%的記錄,並修改雇員的工資為原來工資的101%
只有merge可以同時insert和update
insert語句可以有選擇性的插入多條記錄到多張表,但是沒有辦法去update記錄。
Which option should be used to perform this task most efficiently?
A. MERGE (right)
B. Unconditional INSERT
沒有update功能
C. Conditional ALL INSERT
沒有update功能
D. Conditional FIRST INSERT
沒有update功能
59. Which statement is true regarding the ROLLUP operator specified in the GROUP BY clause of a SQL statement?
A. It produces only the subtotals for the groups specified in the GROUP BY clause.
翻譯: 他只對在groupby條件中指定的分組產生分類匯總
解釋: rollup會自右向左對每一列進行匯總
B. It produces only the grand totals for the groups specified in the GROUP BY clause.
翻譯: 他只對groupby條件中指定的分組做總和
解釋: rollup會自右向左對每一列進行匯總
C. It produces higher-level subtotals, moving from right to left through the list of grouping columns specified in the GROUP BY clause. (right)
翻譯: rollup會自右向左對分組列表中的列進行高水平的匯總
D. It produces higher-level subtotals, moving in all the directions through the list of grouping columns specified in the GROUP BY clause.
翻譯: rollup會全方向的對分組列表中的列進行高水平的匯總
解釋: rollup只會從右向左
60. View the Exhibit and examine DEPARTMENTS and the LOCATIONS tables.
Evaluate the following SQL statement:
SELECT location_id, city
FROM locations l
WHERE NOT EXISTS (
SELECT location_id
FROM departments
WHERE location_id <> l.location_id
);
This statement was written to display LOCATION_ID and CITY where there are no departments located.
要求顯示沒有部門的城市
sql的流程是:
從location表中找出1條記錄,
查詢子查詢是否有返回結果
子查詢的結果是返回department表中不在外查詢中得到的城市的部門信息,一般來說子查詢肯定存在返回值
所以not exists一個非空集合返回false,也就是說該查詢得不到任何結果
Which statement is true regarding the execution and output of the command?
A. The statement would execute and would return the desired results.
返回空集,沒有得到想要的結果
B. The statement would not execute because the = comparison operator is missing in the WHERE clause of the outer query.
exists只判斷子查詢返回的集合是否為空,並不針對字段,所以加上等號反而出錯
C. The statement would execute but it will return zero rows because the WHERE clause in the inner query should have the = operator instead of <>.(right)
等號替換掉不等號,子查詢將會搜索出在location_id上的部門的集合,然后not exists就可以得到沒有部門的 location_id了
D. The statement would not execute because the WHERE clause in the outer query is missing the column name for comparison with the inner query result.
exists只判斷子查詢返回的集合是否為空,並不針對字段,所以加上列名反而出錯