ocp培训:ocp 10g和11g 1z0 047考试题库中文解析(2)

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操作 [lj1] ,也不能创建索引
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. 在产生聚合时会从右向左逐个对每一列进行汇总,而不是所有可能的方向。

 [lj1]SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,
 数据定义语言DDL,数据控制语言DCL。
 1 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句,WHERE 子句组成的查询块:
 SELECT <字段名表> FROM <表或视图名> WHERE <查询条件> 2 数据操纵语言
 数据操纵语言DML主要有三种形式:
 1) 插入:INSERT 2) 更新:UPDATE 3) 删除:DELETE 3 数据定义语言DDL 数据定义语言DDL用来创建数据库中的各种对象-----表、视图、
 索引、同义词、聚簇等如:
 CREATE TABLE/VIEW/INDEX/SYN/CLUSTER | | | | | 表 视图 索引 同义词 簇
 4 数据控制语言DCL 数据控制语言DCL用来授予或回收访问数据库的某种特权,并控制
 数据库操纵事务发生的时间及效果,对数据库实行监视等。如:
 1) GRANT:授权。
 2) ROLLBACK [WORK] TO [SAVEPOINT]:回退到某一点。
 回滚---ROLLBACK 回滚命令使数据库状态回到上次最后提交的状态。其格式为:
 SQL>ROLLBACK; 3) COMMIT [WORK]:提交。
 在数据库的插入、删除和修改操作时,只有当事务在提交到数据
 库时才算完成。在事务提交前,只有操作数据库的这个人才能有权看
 到所做的事情,别人只有在最后提交完成后才可以看到。
 提交数据有三种类型:显式提交、隐式提交及自动提交。下面分
 别说明这三种类型。
 (1) 显式提交
 用COMMIT命令直接完成的提交为显式提交。其格式为:
 SQL>COMMIT;
 (2) 隐式提交
 用SQL命令间接完成的提交为隐式提交。这些命令是:
 ALTER,AUDIT,COMMENT,CONNECT,CREATE,DISCONNECT,DROP,
 EXIT,GRANT,NOAUDIT,QUIT,REVOKE,RENAME。
 (3) 自动提交
 若把AUTOCOMMIT设置为ON,则在插入、修改、删除语句执行后,
 系统将自动进行提交,这就是自动提交。其格式为:
 SQL>SET AUTOCOMMIT ON;

你可能感兴趣的:(OCP)