ocp 10g和11g 1z0 047考试题库中文解析(3)

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戳,不是时间跨度

你可能感兴趣的:(OCP)