ocp 1Z0-047 61-130题解析
61. Evaluate the following SQL statements that are issued in the given order:
CREATE TABLE emp
(emp_no NUMBER(2) CONSTRAINT emp_emp_no_pk PRIMARY KEY,
ename VARCHAR2(15),
salary NUMBER(8,2),
mgr_no NUMBER(2) CONSTRAINT emp_mgr_fk REFERENCES emp);
ALTER TABLE emp DISABLE CONSTRAINT emp_emp_no_pk CASCADE;
ALTER TABLE emp ENABLE CONSTRAINT emp_emp_no_pk;
What would be the status of the foreign key EMP_MGR_FK?
A. It would be automatically enabled and deferred.
B. It would be automatically enabled and immediate.
C. It would remain disabled and has to be enabled manually using the ALTER
TABLE command.
D. It would remain disabled and can be enabled only by dropping the foreign
key constraint and recreating it.
Answer: C
CREATE TABLE emp
(emp_no NUMBER(2) CONSTRAINT emp_emp_no_pk PRIMARY KEY,
ename VARCHAR2(15),
salary NUMBER(8,2),
mgr_no NUMBER(2) CONSTRAINT emp_mgr_fk REFERENCES emp);
1:insert into emp values(1,'tt',1,2);
ORA-02291: 违反完整约束条件 (SYS.EMP_MGR_FK)
2:insert into emp values(1,'tt',1,1);
ok
3:ALTER TABLE emp DISABLE CONSTRAINT emp_emp_no_pk CASCADE;
4:insert into emp values(1,'tt',1,3);
ok,说明主键失效,外键也失效
5:delete from emp where emp_no=1 and mgr_no=1;
ALTER TABLE emp ENABLE CONSTRAINT emp_emp_no_pk;
insert into emp values(1,'tt',1,4);
ORA-00001: 违反唯一约束条件 (SYS.EMP_EMP_NO_PK)
说明主键已经生效
insert into emp values(2,'tt',1,4);
ok,说明外键仍然失效
6:alter table emp enable constraint emp_mgr_fk(emp_no);
ORA-02298: 无法验证 (SYS.EMP_MGR_FK) - 未找到父项关键字
62. View the Exhibit and examine the structure of the LOCATIONS and
DEPARTMENTS tables.
Which SET operator should be used in the blank space in the following SQL
statement to display the cities that have departments located in them?
SELECT location_id, city
FROM locations
____
SELECT location_id, city
FROM locations JOIN departments
USING(location_id);
A. UNION
B. MINUS
C. INTERSECT
D. UNION ALL
Answer: C
INTERSECT:交集
63. Which CREATE TABLE statement is valid?
A. CREATE TABLE ord_details
(ord_no NUMBER(2) PRIMARY KEY,item_no NUMBER(3) PRIMARY KEY,
ord_date date NOT NULL);
B.CREATE TABLE ord_details
(ord_no NUMBER(2) UNIQUE, NOT NULL,
item_no NUMBER(3),ord_date date DEFAULT SYSDATE NOT NULL);
C. CREATE TABLE ord_details
(ord_no NUMBER(2) ,item_no NUMBER(3),
ord_date date DEFAULT NOT NULL,CONSTRAINT ord_uq UNIQUE (ord_no),
CONSTRAINT ord_pk PRIMARY KEY (ord_no));
D. CREATE TABLE ord_details
(ord_no NUMBER(2),item_no NUMBER(3),
ord_date date DEFAULT SYSDATE NOT NULL,
CONSTRAINT ord_pk PRIMARY KEY (ord_no, item_no));
Answer: D
64. Evaluate the following SELECT statement and view the Exhibit to examine
its output:
SELECT constraint_name, constraint_type, search_condition,
r_constraint_name, delete_rule, status
FROM user_constraints WHERE table_name = ORDERS
Which two statements are true about the output? (Choose two.)
A. In the second column, indicates a check constraint.
B. The STATUS column indicates whether the table is currently in use.
C. The R_CONSTRAINT_NAME column gives the alternative name for the
constraint.
D. The column DELETE_RULE decides the state of the related rows in the child
table when the corresponding row is deleted from the parent table.
Answer: AD
Indicates:指示 Alternative:选择
CONSTRAINT_NAME CONSTRAINT_TYPE R_CONSTRAINT_NAME STATUS
------------------------ --------------- ------------------ --------
PK_CRUISE P ENABLED
FK_CRUISES_CRUISE_TYPES R PK_CRUISE_TYPE_ID ENABLED
FK_CRUISES_SHIPS R PK_SHIP ENABLED
FK_CRUISES_EMPLOYEES R PK_EMPLOYEES ENABLED
constraint_type的值为 'R '的表示your table受到其它表的约束,即your table
是从表, r_constraint_name就是reference constraint name 外键约束的名字
选项D的意思是否是DELETE级联
65. Which statement is true regarding Flashback Version Query?
A. It returns versions of rows only within a transaction.
B. It can be used in subqueries contained only in a SELECT statement.
C. It will return an error if the undo retention time is less than the lower
bound time or SCN specified.
D. It retrieves all versions including the deleted as well as subsequently
reinserted versions of the rows.
Answer: D
通过flashback version query 来查到之前的“历史变化”数据。 Flashback version query
是通过from 语句的扩展语句 versions between. 有两种形式的versions between:
VERSIONS BETWEEN TIMESTAMP [lower bound] AND [upper bound]
VERSIONS BETWEEN SCN [lower bound] AND [upper bound]
lower bound/ upper bound 可以是具体的timestamp/scn, 也可以是关键字
minvalue/maxvalue. 这些关键字让Oracle 去找到所有的versions, 当然这要受制于
undo_retention 参数设置的大小,毕竟这部分信息是放在undo segment 上的。
SQL> select x, y, z
from fbt VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE
order by y;
Sql>select x, y, z from fbt VERSIONS BETWEEN scn 54347743 AND 64347768 order by y;
ORA-08181: 指定的编号不是有效的系统更改号 (解释C 选项,确实会报错,只能证明跟
UNDO_RETENTION 值有关,但该值比lower scn 小就会报错,还不一定了)
参数UNDO_RETENTION=n,决定了能往前闪回的最大时间,值越大就需要越多Undo 空间。
Subsequently:随后
66. Which two statements are true regarding multiple-row subqueries? (Choose
two.)
A. They can contain group functions.
B. They always contain a subquery within a subquery.
C. They use the < ALL operator to imply less than the maximum.
D. They can be used to retrieve multiple rows from a single table only.
E. They should not be used with the NOT IN operator in the main query if NULL
is likely to be a part of the result of the subquery.
Answer: AE
SQL> select dest,revenue from test where revenue in (
select 4000 from test union select null from dual);
DEST REVENUE
---------- ----------
wenzhou 4000
SQL> select dest,revenue
from test where revenue not in (
select 4000 from test union select null from dual);
未选定行
SQL> select dest,revenue
from test where revenue not in (select null from dual);
未选定行
可以结论:只要子查询里有空值,在主查询就不能用not in,因为不能返回任何值。
67. View the Exhibit and examine the structure of the ORDERS table. The
columns ORDER_MODE and ORDER_TOTAL have the default values 'direct' and 0
respectively.Which two INSERT statements are valid? (Choose two.)
A. INSERT INTO orders
VALUES (1, '09mar2007','online','',1000);
B. INSERT INTO orders
(order_id,order_date,order_mode,customer_id,order_total)
VALUES(1,TO_DATE(NULL), 'online', 101, NULL);
C. INSERT INTO
(SELECT order_id,order_date,customer_id FROM orders)
VALUES (1,'09mar2007',101);
D. INSERT INTO orders
VALUES (1,'09mar2007',DEFAULT, 101, DEFAULT);
E. INSERT INTO orders
(order_id,order_date,order_mode,order_total)
VALUES (1,'10mar2007','online',1000);
Answer: CD
Respectively:分别
非空的字段一定要插入数据
SQL> insert into (select a from test) values(3);
68. The following are the steps for a correlated subquery, listed in random
order:
1) The WHERE clause of the outer query is evaluated.
2) The candidate row is fetched from the table specified in the outer query.
3) The procedure is repeated for the subsequent rows of the table, till all
the rows are processed.
4) Rows are returned by the inner query, after being evaluated with the value
from the candidate row in the outer query.
Identify the option that contains the steps in the correct sequence in which
the Oracle server evaluates a correlated subquery.
A. 4, 2, 1, 3
B. 4, 1, 2, 3
C. 2, 4, 1, 3
D. 2, 1, 4, 3
Answer: C
Correlated:相互关联 evaluated:估价 candidate:候选人 process:处理
select (select t2.name from t2 where t2.did=t1.did) from t1
()里面的select t2.name from t2 where t2.did=t1.did就是inner outer
而()外面的select (select t2.name from t2 where t2.did=t1.did) from t1 就
属于outer query
69. View the Exhibit and examine the structure of the EMPLOYEES table.
Evaluate the following SQL statement:
SELECT employee_id, last_name, job_id, manager_id
FROM employees START WITH employee_id = 101
CONNECT BY PRIOR employee_id=manager_id;
Which statement is true regarding the output for this command?
A. It would return a hierarchical output starting with the employee whose
EMPLOYEE_ID is 101, followed by his or her peers.
B. It would return a hierarchical output starting with the employee whose
EMPLOYEE_ID is 101, followed by the employee to whom he or she reports.
C. It would return a hierarchical output starting with the employee whose
EMPLOYEE_ID is 101,followed by employees below him or her in the hierarchy.
D. It would return a hierarchical output starting with the employee whose
EMPLOYEE_ID is101, followed by employees up to one level below him or her
in the hierarchy.
Answer: C
PRIOR 在那边决定那边是父亲,决定是向上还是向下搜索
70. Which two statements are true about the GROUPING function? (Choose two.)
A. It is used to find the groups forming the subtotal in a row.
B. It is used to identify the NULL value in the aggregate functions.
C. It is used to form the group sets involved in generating the totals and
subtotals.
D. It can only be used with ROLLUP and CUBE operators specified in the GROUP
BY clause.
Answer: AD
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.
71. Given below is a list of datetime data types and examples of values stored
in them in a random order:
Datatype Example
1)INTERVAL YEAR TO MONTH a) '20030415 8:00:00 8:00'
2)TIMESTAMP WITH LOCAL TIME ZONE b) '+06 03:30:16.000000'
3)TIMESTAMP WITH TIME ZONE c) '17JUN0312.00.00.000000 AM'
4)INTERVAL DAY TO SECOND d) '+0200'
Identify the option that correctly matches the data types with the values.
A. 1d,2c,3a,4b
B. 1b,2a,3c,4d
C. 1b,2a,3d,4c
D. 1d,2c,3b,4a
Answer: A
Eg:对于 TIMESTAMP WITH LOCAL TIME ZONE 类型如下结果
SQL> SELECT TO_TIMESTAMP_TZ('17-04-2013 16:45:30','DD-MM-RRRR
HH24:MI:SS') "Time" FROM DUAL;
Time
----------------------------------------------------------------------
17-4月 -13 04.45.30.000000000 下午 +08:00
72. View the Exhibit and examine the description of the PRODUCT_INFORMATION
table.You want to display the expiration date of the warranty for a product.
Which SQL statement would you execute?
A. SELECT product_id, SYSDATE + warranty_period
FROM product_information;
B. SELECT product_id, TO_YMINTERVAL(warranty_period)
FROM product_information;
C. SELECT product_id, TO_YMINTERVAL(SYSDATE) + warranty_period
FROM product_information;
D. SELECT product_id, TO_YMINTERVAL(SYSDATE + warranty_period)
FROM product_information;
Answer: A
Expiration:满期 warranty:授权
to_yminterval Output: A value in the INTERVAL YEAR TO MONTHS datatype.
SQL> select to_yminterval('14-12') event_time from dual;
第 1 行出现错误:
ORA-01843: 无效的月份
SQL> select to_yminterval('14-11') event_time from dual;
EVENT_TIME
--------------------------------------------------------
+000000014-11
73. View the Exhibit and examine the structure of the ORDERS table.
NEW_ORDERS is a new table with the columns ORD_ID, ORD_DATE, CUST_ID, and
ORD_TOTAL that have the same data types and size as the corresponding columns
in the ORDERS table.Evaluate the following INSERT statement:
INSERT INTO new_orders (ord_id, ord_date, cust_id, ord_total)
VALUES(SELECT order_id,order_date,customer_id,order_total
FROM orders WHERE order_date > '31dec1999');
Why would the INSERT statement fail?
A. because column names in NEW_ORDERS and ORDERS tables do not match
B. because the VALUES clause cannot be used in an INSERT with a subquery
C. because the WHERE clause cannot be used in a subquery embedded in an INSERT
statement
D. because the total number of columns in the NEW_ORDERS table does not match
the total number of columns in the ORDERS table
Answer: B
74. View the Exhibit and examine the structure of the ORDER_ITEMS and ORDERS
tables.
You are asked to retrieve the ORDER_ID, PRODUCT_ID, and total price
(UNIT_PRICE multiplied by QUANTITY), where the total price is greater than
50,000.
You executed the following SQL statement:
SELECT order_id, product_id, unit_price*quantity "Total Price"
FROM order_items
WHERE unit_price*quantity > 50000 NATURAL JOIN orders;
Which statement is true regarding the execution of the statement?
A. The statement would execute and provide the desired result.
B. The statement would not execute because the ON keyword is missing in the
NATURAL JOIN clause.
C. The statement would not execute because the WHERE clause is before the
NATURAL JOIN clause.
D. The statement would not execute because the USING keyword is missing in
the NATURAL JOIN
clause.
Answer: C
1: SQL> select deptno,ename from dept natural join emp where deptno>30;
Ok
2: SQL> select deptno,ename from dept where deptno>30 natural join emp;
ORA-00933: SQL 命令未正确结束
自然连接(NATURAL JOIN)是一种特殊的等价连接,它将表中具有相同名称的列
自动进行记录匹配。自然连接不必指定任何同等连接条件。
75. View the Exhibit and examine the structure of the EMPLOYEES table.
You want to know the FIRST_NAME and SALARY for all employees who have the
same manager as that of the employee with the first name 'Neena' and have
salary equal to or greater than that of 'Neena'.
Which SQL statement would give you the desired result?
A. SELECT first_name, salary
FROM employees WHERE (manager_id, salary) >= ALL (SELECT manager_id, salary
FROM employees WHERE first_name = 'Neena' ) AND first_name <> 'Neena';
B. SELECT first_name, salary
FROM employees WHERE (manager_id, salary) >= (SELECT manager_id, salary
FROM employees WHERE first_name = 'Neena' ) AND first_name <> 'Neena';
C. SELECT first_name, salary
FROM employees WHERE (manager_id, salary) >= ANY (SELECT manager_id, salary
FROM employees WHERE first_name = 'Neena' ) AND first_name <> 'Neena';
D. SELECT first_name, salary
FROM employees WHERE ( manager_id = (SELECT manager_id
FROM employees WHERE first_name = 'Neena' )
AND salary >= ( SELECT salary
FROM employees WHERE first_name = 'Neena' ) )
AND first_name <> 'Neena';
Answer: D
(容易错)
76. View the Exhibit and examine the structure of the ORDERS table.
Which UPDATE statement is valid?
A. UPDATE orders SET order_date = '12mar2007',
order_total IS NULL WHERE order_id = 2455;
B. UPDATE orders SET order_date = '12-mar-2007',
order_total = NULL WHERE order_id = 2455;
C. UPDATE orders
SET order_date = '12mar2007' AND order_total = TO_NUMBER(NULL)
WHERE order_id = 2455;
D. UPDATE orders
SET order_date = TO_DATE('12mar2007','ddmonyyyy'),
SET order_total = TO_NUMBER(NULL)
WHERE order_id = 2455;
Answer: B
Null是不能转换的
1:SQL> create table orders(order_id number(12),order_date timestamp(6) with
local time zone,order_total number(2));
2: SQL> insert into orders(order_id) values(1);
3: SQL> UPDATE orders SET order_date = '12-mar-2007',
order_total = NULL WHERE order_id = 1;
第 1 行出现错误:ORA-01843: 无效的月份
4: SQL> UPDATE orders SET order_date = '20-JUN-11 02.03.18.000000 PM',
order_total = NULL WHERE order_id = 1; ok
77. View the Exhibit and examine the descriptions for ORDERS and ORDER_ITEMS
tables.Evaluate the following SQL statement:
SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Order
Amount" FROM order_items oi JOIN orders o
ON oi.order_id = o.order_id GROUP BY CUBE (o.customer_id, oi.product_id);
Which three statements are true regarding the output of this SQL statement?
(Choose three.)
A. It would return the subtotals for the Order Amount of every CUSTOMER_ID.
B. It would return the subtotals for the Order Amount for every PRODUCT_ID.
C. It would return the subtotals for the Order Amount of every PRODUCT_ID
and CUSTOMER_ID as one group.
D. It would return the subtotals for the Order Amount of every CUSTOMER_ID
and PRODUCT_ID as one group.
E. It would return only the grand total for the Order Amount of every
CUSTOMER_ID and PRODUCT_ID as one group.
Answer: ABD
78. View the Exhibit and examine the details of the EMPLOYEES table.
You want to generate a hierarchical report for all the employees who report
to the employee whose EMPLOYEE_ID is 100.
Which SQL clauses would you require to accomplish the task? (Choose all that
apply.)
A. WHERE
B. HAVING
C. GROUP BY
D. START WITH
E. CONNECT BY
Answer: ADE
79. View the Exhibit and examine the data in ORDERS_MASTER and MONTHLY_ORDERS
tables.Evaluate the following MERGE statement:
MERGE INTO orders_master o
USING monthly_orders m
ON (o.order_id = m.order_id)
WHEN MATCHED THEN
UPDATE SET o.order_total = m.order_total
DELETE WHERE (m.order_total IS NULL)
WHEN NOT MATCHED THEN
INSERT VALUES (m.order_id, m.order_total);
What would be the outcome of the above statement?
A. The ORDERS_MASTER table would contain the ORDER_IDs 1 and 2.
B. The ORDERS_MASTER table would contain the ORDER_IDs 1, 2 and 3.
C. The ORDERS_MASTER table would contain the ORDER_IDs 1, 2 and 4.
D. The ORDERS_MASTER table would contain the ORDER_IDs 1, 2, 3 and 4.
Answer: C
ORDER_ID=3的记录因匹配而删除了,因为没有匹配的记录ORDER_ID=4不会被删除
80. Evaluate the following ALTER TABLE statement:
ALTER TABLE orders SET UNUSED order_date;
Which statement is true?
A. The DESCRIBE command would still display the ORDER_DATE column.
B. ROLLBACK can be used to get back the ORDER_DATE column in the ORDERS table.
C. The ORDER_DATE column should be empty for the ALTER TABLE command to
execute successfully.
D. After executing the ALTER TABLE command, you can add a new column called
ORDER_DATE to the ORDERS table.
Answer: D
81. View the Exhibit and examine the ORDERS table.
The ORDERS table contains data and all orders have been assigned a customer
ID. Which statement would add a NOT NULL constraint to the CUSTOMER_ID
column?
A. ALTER TABLE orders ADD CONSTRAINT orders_cust_id_nn NOT NULL
(customer_id);
B. ALTER TABLE orders
MODIFY customer_id CONSTRAINT orders_cust_id_nn NOT NULL;
C. ALTER TABLE orders
MODIFY CONSTRAINT orders_cust_id_nn NOT NULL (customer_id);
D. ALTER TABLE orders
ADD customer_id NUMBER(6)CONSTRAINT orders_cust_id_nn NOT NULL;
Answer: B
82. Which three statements indicate the end of a transaction? (Choose three.)
A. after a COMMIT is issued
B. after a ROLLBACK is issued
C. after a SAVEPOINT is issued
D. after a SELECT statement is issued
E. after a CREATE statement is issued
Answer: ABE
Indicate:显示
CREATE 属于ddl语句,隐式提交
83. View the Exhibit and examine the structure of the ORDERS table.
You have to display ORDER_ID, ORDER_DATE, and CUSTOMER_ID for all those
orders that were placed after the last order placed by the customer whose
CUSTOMER_ID is 101.Which query would give you the desired output?
A. SELECT order_id, order_date FROM orders
WHERE order_date > ALL (SELECT MAX(order_date)
FROM orders ) AND
customer_id = 101;
B. SELECT order_id, order_date FROM orders
WHERE order_date > ANY (SELECT order_date
FROM orders WHERE customer_id = 101);
C. SELECT order_id, order_date FROM orders
WHERE order_date > ALL (SELECT order_date
FROM orders WHERE customer_id = 101);
D. SELECT order_id, order_date FROM orders
WHERE order_date IN (SELECT order_date
FROM orders
WHERE customer_id = 101);
Answer: C
题目: the last order placed 可理解为日期最大的,所以用>ALL
Some在此表示满足其中一个的意义,是用or串起来的比较从句。
Any也表示满足其中一个的意义,也是用or串起来的比较从句,区别是any一般用在
非“=”的比较关系中,这也很好理解,英文中的否定句中使用any肯定句中使用
sone,这一点是一样的。
All则表示满足其其中所有的查询结果的含义,使用and串起来的比较从句。
1:select ename,sal From emp
Where sal > any(select sal from emp where deptno = 10);
只要比部门号为10的员工中的那个工资最少的员工的工资高就满足条件
2:select ename,sal
From emp Where sal > all(select sal from emp where deptno = 20);
找到比部门号为20的员工的所有员工的工资都要高的员工,也就是比那个工资最高
的员工的还要高的员工
84. You need to create a table with the following column specifications:
1. Employee ID (numeric data type) for each employee
2. Employee Name, (character data type) which stores the employee name
3. Hire date, to store the date when the employee joined the organization
4. Status (character data type). It should contain the value if no data is
entered.
5. Resume (character large object [CLOB] data type), which would contain the
resume submitted by the employee
Which is the correct syntax 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 1_EMP
(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
表名不能以数字开头
85. The details of the order ID, order date, order total, and customer ID
are obtained from the ORDERS table. If the order value is more than 30000,
the details have to be added to the LARGE_ORDERS table.
The order ID, order date, and order total should be added to the ORDER_HISTORY
table, and order ID and customer ID should be added to the CUST_HISTORY table.
Which multitable INSERT statement would you use?
A. Pivoting INSERT
B. Unconditional INSERT
C. Conditional ALL INSERT
D. Conditional FIRST INSERT
Answer: C
1: 无条件 INSERT ALL
从 EMPLOYEES 中选择 EMPLOYEE_ID 大于200的雇员 EMPLOYEE_ID, HIRE_DATE, SALARY, 和
MANAGER_ID 值
用多表 INSERT 插入这些值到 SAL_HISTORY 和 MGR_HISTORY 表中
INSERT ALL
INTO sal_history VALUES(EMPID,HIREDATE,SAL)
INTO mgr_history VALUES(EMPID,MGR,SAL)
SELECT employee_id EMPID, hire_date HIREDATE,
salary SAL, manager_id MGR
FROM employees
WHERE employee_id > 200;
The example in the slide inserts rows into both the SAL_HISTORY and the MGR_HISTORY
tables.//插入到两个表中.
2: 条件INSERT ALL
从 EMPLOYEES 表中选择 EMPLOYEE_ID 大于200的那些雇员的 EMPLOYEE_ID, HIRE_DATE,
SALARY 和 MANAGER_ID 值
如果 SALARY 大于 $10,000,用一个条件多表 INSERT语句插入这些值到 SAL_HISTORY 表中
如果 MANAGER_ID 大于 200,用一个多表 INSERT 语句插入这些值到 MGR_HISTORY 表中
INSERT ALL
WHEN SAL > 10000 THEN
INTO sal_history VALUES(EMPID,HIREDATE,SAL)
WHEN MGR > 200 THEN
INTO mgr_history VALUES(EMPID,MGR,SAL)
SELECT employee_id EMPID,hire_date HIREDATE,
salary SAL, manager_id MGR
FROM employees
WHERE employee_id > 200;
3: 条件FIRST INSERT
从 EMPLOYEES 表中选择 DEPARTMENT_ID , SUM(SALARY) 和 MAX(HIRE_DATE)
如果 SUM(SALARY) 大于 $25,000 则用一个条件 FIRST 多表 INSERT 插入这些值到
SPECIAL_SAL 表中
如果第一个 WHEN 子句的值为 true,则该行的后面的 WHEN 子句被跳过
对于那些不满足第一个 WHEN 条件的行,用一个条件多表 INSERT 基于HIRE_DATE 列的值插
入 HIREDATE_HISTORY_00, 或 HIREDATE_HISTORY_99, 或 HIREDATE_HISTORY 表,根据
HIREDATE列的值.
INSERT FIRST
WHEN SAL > 25000 THEN
INTO special_sal VALUES(DEPTID, SAL)
WHEN HIREDATE like ('%00%') THEN
INTO hiredate_history_00 VALUES(DEPTID,HIREDATE)
WHEN HIREDATE like ('%99%') THEN
INTO hiredate_history_99 VALUES(DEPTID, HIREDATE)
ELSE
INTO hiredate_history VALUES(DEPTID, HIREDATE)
SELECT department_id DEPTID, SUM(salary) SAL,
MAX(hire_date) HIREDATE
FROM employees
GROUP BY department_id;
4: 重点INSERT
支持从非关系数据库表中接受一组销售记录, SALES_SOURCE_DATA 的格式如下:
EMPLOYEE_ID, WEEK_ID, SALES_MON, SALES_TUE, SALES_WED, SALES_THUR, SALES_FRI
你可能想要以一种典型的相关格式存储这些记录到 SALES_INFO 表中:
EMPLOYEE_ID, WEEK, SALES
使用 pivoting INSERT,从非关系数据库表转换销售记录集到关系格式
INSERT ALL
INTO sales_info VALUES (employee_id,week_id,sales_MON)
INTO sales_info VALUES (employee_id,week_id,sales_TUE)
INTO sales_info VALUES (employee_id,week_id,sales_WED)
INTO sales_info VALUES (employee_id,week_id,sales_THUR)
INTO sales_info VALUES (employee_id,week_id,sales_FRI)
SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE,
sales_WED, sales_THUR,sales_FRI
FROM sales_source_data;
将表SALES_SOURCE_DATA的一行转换为表SALES_INFO的五条记录(关系表)
86. View the Exhibit and examine the description of the EMPLOYEES table.
Evaluate the following SQL statement:
SELECT first_name, employee_id, NEXT_DAY(ADD_MONTHS(hire_date, 6),1)
"Review" FROM employees;
The query was written to retrieve the FIRST_NAME, EMPLOYEE_ID, and review
date for employees.The review date is the first Monday after the completion
of six months of the hiring. The NLS_TERRITORY parameter is set to AMERICA
in the session.Which statement is true regarding this query?
A. The query would execute to give the desired output.
B. The query would not execute because date functions cannot be nested.
C. The query would execute but the output would give review dates that are
Sundays.
D. The query would not execute because the NEXT_DAY function accepts a string
as argument.
Answer: C
NEXT_DAY的第2个参数可以是数字1-7,分别表示周日到周六
例如取下一个星期六 select next_day(sysdate,7) FROM DUAL;
87. View the Exhibit and examine the structure of the EMPLOYEES table.
You want to display all employees and their managers having 100 as the
MANAGER_ID. You want the output in two columns: the first column would have
the LAST_NAME of the managers and the second column would have LAST_NAME
of the employees. Which SQL statement would you execute?
A. SELECT m.last_name "Manager", e.last_name "Employee"
FROM employees m JOIN employees e
ON m.employee_id = e.manager_id
WHERE m.manager_id=100;
B. SELECT m.last_name "Manager", e.last_name "Employee"
FROM employees m JOIN employees e
ON m.employee_id = e.manager_id
WHERE e.manager_id=100;
C. SELECT m.last_name "Manager", e.last_name "Employee"
FROM employees m JOIN employees e
ON e.employee_id = m.manager_id
WHERE m.manager_id=100;
D. SELECT m.last_name "Manager", e.last_name "Employee"
FROM employees m JOIN employees e
WHERE m.employee_id = e.manager_id AND e.manager_id=100;
Answer: B
and their managers having 100 决定了是从雇员表里找他们的经理
A跟C效果是一样的
1:SQL> select * from emp;
EMP_NO ENAME SALARY MGR_NO
---------- --------------- ---------- ----------
1 tt 1 3
2 tt 1 4
3 dd 1 2
2: SQL> select m.ename "Man",e.ename "Emp"
from emp m join emp e
on m.emp_no=e.mgr_no
where e.mgr_no=2;
Man Emp
--------------- ---------------
tt dd
3: SQL> select m.ename "Man",e.ename "Emp"
from emp m join emp e
on m.emp_no=e.mgr_no
where m.mgr_no=2;
Man Emp
--------------- ---------------
dd tt
4: SQL> select m.ename "Man",e.ename "Emp"
from emp m join emp e
where m.emp_no=e.mgr_no
and e.mgr_no=2;
第 3 行出现错误: ORA-00905: 缺失关键字
88. View the Exhibit1 and examine the descriptions of the EMPLOYEES and
DEPARTMENTS tables.The following SQL statement was executed:
SELECT e.department_id, e.job_id, d.location_id, sum(e.salary) total,
GROUPING(e.department_id) GRP_DEPT,GROUPING(e.job_id) GRP_JOB,
GROUPING(d.location_id) GRP_LOC FROM employees e JOIN departments d
ON e.department_id = d.department_id
GROUP BY ROLLUP (e.department_id, e.job_id, d.location_id);
View the Exhibit2 and examine the output of the command.
Which two statements are true regarding the output? (Choose two.)
A. The value 1 in GRP_LOC means that the LOCATION_ID column is taken into
account to generate the subtotal.
B. The value 1 in GRP_JOB and GRP_LOC means that JOB_ID and LOCATION_ID
columns are not taken into account to generate the subtotal.
C. The value 1 in GRP_JOB and GRP_LOC means that the NULL value in JOB_ID
and LOCATION_ID columns are taken into account to generate the subtotal.
D. The value 0 in GRP_DEPT, GRP_JOB, and GRP_LOC means that DEPARTMENT_ID,
JOB_ID, and LOCATION_ID columns are taken into account to generate the
subtotal.
Answer: BD
GROUPING函数可以接受一列,返回0或者1。GROUPING只能在使用ROLLUP或CUBE的查询中使用。
当需要在返回空值的地方显示某个值时,GROUPING()就非常有用。
1、在ROLLUP中对单列使用GROUPING()
SQL> select division_id,sum(salary)
from employees2
group by rollup(division_id)
order by division_id;
DIV SUM(SALARY)
--- -----------
BUS 1610000
OPE 1320000
SAL 4936000
SUP 1015000
8881000
加上GROUPING来看看
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。
什么地方用:rollup 和cube带来的一个问题是,在返会的结果中如何能准确区分出那些是小
计,哪些是汇总数据呢。这点可以使用grouping和grouping_id函数解决。
容易被C选项误导,如果该列没有参加计算,则为1,并不是说该列值为空
89. View the Exhibit and examine the description of the DEPARTMENTS and
EMPLOYEES tables.To retrieve data for all the employees for their EMPLOYEE_ID,
FIRST_NAME, and DEPARTMENT NAME,the following SQL statement was written:
SELECT employee_id, first_name, department_name
FROM employees
NATURAL JOIN departments;
The desired output is not obtained after executing the above SQL statement.
What could be the reason for this?
A. The NATURAL JOIN clause is missing the USING clause.
B. The table prefix is missing for the column names in the SELECT clause.
C. The DEPARTMENTS table is not used before the EMPLOYEES table in the FROM
clause.
D. The EMPLOYEES and DEPARTMENTS tables have more than one column with the
same column name and data type.
Answer: D
Obtained:获得
本题的意思是问为什么没有获得想要的结果,因为这两个表除了department_id相同外,还有
manager_id字段相同,从而过滤了记录.
自然连接是在两张表中寻找那些数据类型和列名都相同的字段,然后自动地将他们连接起来,
并返回所有符合条件按的结果。来看一下自然连接的例子。
Select emp.ename,dept.dname From emp natural join dept;
这里我们并没有指定连接的条件,实际上oracle为我们自作主张的将,emp中的deptno和dept
中的deptno做了连接。也就是实际上相当于
Select emp.ename,dept.dname From emp join dept on emp.deptno = dept.deptno;
因为这两张表的这两个字段deptno的类型个名称完全相同。所以使用natural join时被自然的
连接在一起了。
另外:
1.如果做自然连接的两个表的有多个字段都满足有相同名称个类型,那么他们会被作为自然连
接的条件。
2.如果自然连接的两个表仅是字段名称相同,但数据类型不同,那么将会返回一个错误。
3.由于oracle中可以进行这种非常简单的natural join,我们在设计表时,应该尽量在不同表
中具有相同含义的字段使用相同的名字和数据类型。以方便以后使用natural join
90. View the Exhibit and examine the descriptions of the DEPT and LOCATIONS
tables.You want to update the CITY column of the DEPT table for all the rows
with the corresponding value in the CITY column of the LOCATIONS table for
each department.Which SQL statement would you execute to accomplish the task?
A. UPDATE dept d SET city = ANY (SELECT city FROM locations l);
B. UPDATE dept d SET city = (SELECT city FROM locations l)
WHERE d.location_id = l.location_id;
C. UPDATE dept d SET city = (SELECT city FROM locations l WHERE d.location_id
= l.location_id);
D. UPDATE dept d SET city = ALL (SELECT city FROM locations l
WHERE d.location_id = l.location_id);
Answer: C
91. View the Exhibit and examine the data in the LOCATIONS table.
Evaluate the following SQL statement:
SELECT street_address
FROM locations WHERE REGEXP_INSTR(street_address,'[^[:alpha:]]') = 1;
Which statement is true regarding the output of this SQL statement?
A. It would display all the street addresses that do not have a substring
'alpha'.
B. It would display all the street addresses where the first character is
a special character.
C. It would display all the street addresses where the first character is
a letter of the alphabet.
D. It would display all the street addresses where the first character is
not a letter of the alphabet.
Answer: D
REGEXP_INSTR 有6个参数:
第一个是输入的字符串 第二个是正则表达式
第三个是标识从第几个字符开始正则表达式匹配。(默认为1)
第四个是标识第几个匹配组。(默认为1)
第五个是指定返回值的类型,如果该参数为0,则返回值为匹配位置的第一个字符,如果该值为
非0则返回匹配值的最后一个位置。
第六个是是取值范围:
i:大小写不敏感; c:大小写敏感; n:点号 . 不匹配换行符号;
m:多行模式; x:扩展模式,忽略正则表达式中的空白字符。
正则表达式规则: [^. . .] --- A “not equals” bracket expression
| --- Logical OR.
. --- Match any character in the database character set.
$ --- End of line anchor
^ --- Beginning of line anchor.
+ ---Match one or more occurrences of the preceding subexpression.
SQL> select REGEXP_INSTR('1234aa','[:alpha:]') from dual; 第一个字母的位置
REGEXP_INSTR('1234AA','[:ALPHA:]')
----------------------------------
5
SQL> select REGEXP_INSTR('1234aa','[^[:alpha:]]') from dual; 第一个非字母的位置
REGEXP_INSTR('1234AA','[^[:ALPHA:]]')
-------------------------------------
1
做题的是注意细节,有[^表示非的意思
92. Evaluate the following expression using meta character for regular
expression:'[^Ale|ax.r$]'
Which two matches would be returned by this expression? (Choose two.)
A. Alex
B. Alax
C. Alxer
D. Alaxendar
E. Alexender
Answer: DE
正则表达式规则: [^. . .] --- A “not equals” bracket expression
| --- Logical OR.
. --- Match any character in the database character set.
$ --- End of line anchor
^ --- Beginning of line anchor.
+ ----Match one or more occurrences of the preceding subexpression.
[^. . .] 是取相反的意思啊,疑问
93. The ORDERS table belongs to the user OE. OE has granted the SELECT
privilege on the ORDERS table to the user HR.
Which statement would create a synonym ORD so that HR can execute the
following query successfully?
SELECT * FROM ord;
A. CREATE SYNONYM ord FOR orders; This command is issued by OE.
B. CREATE PUBLIC SYNONYM ord FOR orders; This command is issued by OE.
C. CREATE SYNONYM ord FOR oe.orders; This command is issued by the database
administrator.
D. CREATE PUBLIC SYNONYM ord FOR oe.orders; This command is issued by the
database administrator.
Answer: D
Issue:发行
94. View the Exhibit and examine the description of the EMPLOYEES and
DEPARTMENTS tables.You want to display the LAST_NAME for the employees,
LAST_NAME for the manager of the employees,and the DEPARTMENT_NAME for the
employees having 100 as MANAGER_ID. The following SQL
statement was written:
SELECT m.last_name "Manager", e.last_name "Employee", department_name
"Department" FROM employees m JOIN employees e
ON (m.employee_id = e.manager_id)
WHERE e.manager_id=100 JOIN departments d
ON (e.department_id = d.department_id);
Which statement is true regarding the output of this SQL statement?
A. The statement would provide the desired results.
B. The statement would not execute because the ON clause is written twice.
C. The statement would not execute because the WHERE clause is wrongly placed.
D. The statement would not execute because the self join uses the ON clause
instead of the USING clause.
Answer: C
SQL> select m.ename "Man",e.ename "Emp"
2 from emp m join emp e
3 on m.emp_no=e.mgr_no
4 where m.mgr_no=2 join dept d
5 on(m.emp_no=d.deptid);
第 4 行出现错误:
ORA-00933: SQL 命令未正确结束
SQL> select m.ename "Man",e.ename "Emp"
2 from emp m join emp e
3 on m.emp_no=e.mgr_no
4 join dept d
5 on(m.emp_no=d.deptid)
6 where m.mgr_no=2 ;
Man Emp
dd tt
95. Evaluate the following DELETE statement:
DELETE FROM orders;
There are no other uncommitted transactions on the ORDERS table.
Which statement is true about the DELETE statement?
A. It removes all the rows in the table and allows ROLLBACK.
B. It would not remove the rows if the table has a primary key.
C. It removes all the rows as well as the structure of the table.
D. It removes all the rows in the table and does not allow ROLLBACK.
Answer: A
96. View the Exhibit and examine the structure of ORDERS and ORDER_ITEMS
tables.ORDER_ID is the primary key in the ORDERS table. It is also the foreign
key in the ORDER_ITEMS table where in it is created with the ON DELETE CASCADE
option. Which DELETE statement would execute successfully?
A. DELETE order_id FROM orders WHERE order_total < 1000;
B. DELETE orders WHERE order_total < 1000;
C. DELETE FROM orders WHERE (SELECT order_id FROM order_items);
D.DELETE orders o, order_items I WHERE o.order_id = i.order_id;
Answer: B
97. View the Exhibit and examine the description for EMPLOYEES and
DEPARTMENTS tables.Evaluate the following SQL statement:
SELECT e.department_id, e.job_id, d.location_id, sum(e.salary) total
FROM employees e JOIN departments d ON e.department_id = d.department_id
GROUP BY CUBE (e.department_id, e.job_id, d.location_id);
Which two statements are true regarding the output of this command? (Choose
two.)
A. The output would display the total salary for all the departments.
B. The output would display the total salary for all the JOB_IDs in a
department.
C. The output would display only the grand total of the salary for all JOB_IDs
in a LOCATION_ID.
D. The output would display the grand total of the salary for only the groups
specified in the GROUP BY clause.
Answer: AB
98. View the Exhibit and examine the data in EMP and DEPT tables.
In the DEPT table, DEPTNO is the PRIMARY KEY.
In the EMP table, EMPNO is the PRIMARY KEY and DEPTNO is the FOREIGN KEY
referencing the DEPTNO column in the DEPT table.
What would be the outcome of the following statements executed in the given
sequence?
DROP TABLE emp;
FLASHBACK TABLE emp TO BEFORE DROP;
INSERT INTO emp VALUES (2,COTT 10);
INSERT INTO emp VALUES (3,ING 55);
A. Both the INSERT statements would fail because all constraints are
automatically retrieved when the table is flashed back.
B. Both the INSERT statements would succeed because none of the constraints
on the table are automatically retrieved when the table is flashed back.
C. Only the first INSERT statement would succeed because all the constraints
except the primary key constraint are automatically retrieved after a table
is flashed back.
D. Only the second INSERT statement would succeed because all the constraints
except referential integrity constraints that reference other tables are
retrieved automatically after the table is flashed back.
Answer: D
Except:除..外 Referential:参考 integrity:完整
这个题出的很好
99. View the Exhibit and examine the structure of the ORDERS table.
The ORDER_ID column is the PRIMARY KEY in the ORDERS table. Evaluate the
following CREATE TABLE command:
CREATE TABLE new_orders(ord_id, ord_date DEFAULT SYSDATE, cust_id)
AS SELECT order_id,order_date,customer_id FROM orders;
Which statement is true regarding the above command?
A. The NEW_ORDERS table would not get created because the DEFAULT value cannot
be specified in the column definition.
B. The NEW_ORDERS table would get created and only the NOT NULL constraint
defined on the specified columns would be passed to the new table.
C. The NEW_ORDERS table would not get created because the column names in
the CREATE TABLE command and the SELECT clause do not match.
D. The NEW_ORDERS table would get created and all the constraints defined
on the specified columns in the ORDERS table would be passed to the new table.
Answer: B
SQL> create table emp(emp_no number(2) not null,empdate date not null,mgr_no
number(2));
SQL> create table emp_new(emp_no,ord_date default sysdate,mgc_no) as select
emp_no,empdate,mgr_no from emp;
SQL> desc emp_new;
名称 是否为空? 类型
EMP_NO NOT NULL NUMBER(2)
ORD_DATE NOT NULL DATE
MGC_NO NUMBER(2)
100. Which two statements are true regarding the GROUP BY clause in a SQL
statement? (Choose two.)
A. You can use column alias in the GROUP BY clause.
B. Using the WHERE clause after the GROUP BY clause excludes the rows after
creating groups.
C. The GROUP BY clause is mandatory if you are using an aggregate function
in the SELECT clause.
D. Using the WHERE clause before the GROUP BY clause excludes the rows before
creating groups.
E. If the SELECT clause has an aggregate function, then those individual
columns without an aggregate function in the SELECT clause should be included
in the GROUP BY clause.
Answer: DE
Mandatory:强制 aggregate:合计
Order by 才可以用别名,group by 不能用别名
对应C选项,只有求和以为的Select列名需要到group by里,如果没有就不需要
101. Which statement is true regarding synonyms?
A. Synonyms can be created for tables but not views.
B. Synonyms are used to reference only those tables that are owned by another
user.
C. A public synonym and a private synonym can exist with the same name for
the same table.
D. The DROP SYNONYM statement removes the synonym, and the status of the table
on which the synonym has been created becomes invalid.
Answer: C
102. Evaluate the following command:
CREATE TABLE employees
(employee_id NUMBER(2) PRIMARY KEY,
last_name VARCHAR2(25) NOT NULL,
department_id NUMBER(2),job_id VARCHAR2(8),salary NUMBER(10,2));
You issue the following command to create a view that displays the IDs and
last names of the sales staff in the organization:
CREATE OR REPLACE VIEW sales_staff_vu AS
SELECT employee_id, last_name,job_id
FROM employees
WHERE job_id LIKE 'SA_%' WITH CHECK OPTION;
Which statements are true regarding the above view? (Choose all that apply.)
A. It allows you to insert details of all new staff into the EMPLOYEES table.
B. It allows you to delete the details of the existing sales staff from the
EMPLOYEES table.
C. It allows you to update the job ids of the existing sales staff to any
other job id in the EMPLOYEES table.
D.It allows you to insert the IDs, last names and job ids of the sales staff
from the view if it is used in multitable INSERT statements.
Answer: BD
Staff:职员
103. View the Exhibit and examine the structure of EMPLOYEES and JOB_HISTORY
tables.The EMPLOYEES table maintains the most recent information regarding
salary, department, and job for all the employees. The JOB_HISTORY table
maintains the record for all the job changes for the employees. You want to
delete all the records from the JOB_HISTORY table that are repeated in the
EMPLOYEES table. Which two SQL statements can you execute to accomplish the
task? (Choose two.)
A. DELETE FROM job_history j
WHERE employee_id =(SELECT employee_id
FROM employees e WHERE j.employee_id = e.employee_id)
AND job_id = (SELECT job_id FROM employees e
WHERE j.job_id = e.job_id);
B. DELETE FROM job_history j
WHERE (employee_id, job_id) = ALL
(SELECT employee_id, job_id FROM employees e WHERE j.employee_id =
e.employee_id and j.job_id = e.job_id )
C. DELETE FROM job_history j WHERE employee_id =(SELECT employee_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id =
e.job_id )
D. DELETE FROM job_history j
WHERE (employee_id, job_id) = (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id =
e.job_id )
Answer: CD
C,D是同一个意思,而A把删除范围扩大了
104. The user SCOTT who is the owner of ORDERS and ORDER_ITEMS tables issues
the following GRANT command:
GRANT ALL ON orders, order_items TO PUBLIC;
What correction needs to be done to the above statement?
A. PUBLIC should be replaced with specific usernames.
B. ALL should be replaced with a list of specific privileges.
C. WITH GRANT OPTION should be added to the statement.
D. Separate GRANT statements are required for ORDERS and ORDER_ITEMS tables.
Answer: D
grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public)
Eg:
SQL> GRANT ALL ON test,wdz1 TO PUBLIC
第 1 行出现错误:
ORA-00905: 缺失关键字
SQL> GRANT ALL ON test TO PUBLIC;
授权成功。
SQL> GRANT ALL ON wdz1 TO PUBLIC;
授权成功。
105. Given below is a list of functions and the tasks performed by using these
functions, in random order.
Function Usage
1) LPAD a) Used to truncate a column, expression, or value to n decimal
places
2) TRUNC b) Used to remove heading or trailing or both characters from
the character string
3) DECODE c) Pads the character value rightjustified
to a total width of n character positions
4) TRIM d) Used to return the numeric value for position of a named
character from the character string
5) INSTR e) Used to translate an expression after comparing it with each
search value
Which option correctly matches the function names with their usage?
A. 1c,2b,3e,4a,5d
B. 1e,2b,3c,4a,5d
C. 1e,2a,3c,4d,5b
D. 1c,2a,3e,4b,5d
Answer: D
这种题用排除法最快
106. Which statement is true regarding the CUBE operator in the GROUP BY
clause of a SQL statement?
A. It produces only aggregates for the groups specified in the GROUP BY
clause.
B. It finds all the NULL values in the superaggregates for the groups
specified in the GROUP BY clause.
C. It produces 2 n possible superaggregate combinations, if the n columns
and expressions are specified in the GROUP BY clause.
D. It produces n+1 possible superaggregate combinations, if the n columns
and expressions are specified
in the GROUP BY clause.
Answer: C
Aggregates:集合 aggregate:合计 combinations:结合的
107. Which statement is true regarding the SESSION_PRIVS dictionary view?
A. It contains the current object privileges available in the user session.
B. It contains the current system privileges available in the user session.
C. It contains the object privileges granted to other users by the current
user session.
D. It contains the system privileges granted to other users by the current
user session.
Answer: B
A选项为什么不对?
DBA_SYS_PRIVS: 查询某个用户所拥有的系统权限
USER_SYS_PRIVS: 当前用户所拥有的系统权限
SESSION_PRIVS: 当前用户所拥有的全部权限
ROLE_SYS_PRIVS: 某个角色所拥有的系统权限
QL> SELECT * FROM SESSION_PRIVS;(看不到当前用户的对象权限)
CREATE SESSION
CREATE DATABASE LINK
CREATE PROCEDURE
CREATE TRIGGER
CREATE MATERIALIZED VIEW
CREATE TYPE
而select * from dba_tab_privs where grantee='DD'(可以看到对象权限)
108. View the Exhibit and examine the details for the CATEGORIES_TAB table.
Evaluate the following incomplete SQL statement:
SELECT category_name,category_description
FROM categories_tab
You want to display only the rows that have 'harddisks' as part of the string
in the CATEGORY_DESCRIPTION column.
Which two WHERE clause options can give you the desired result? (Choose two.)
A. WHERE REGEXP_LIKE (category_description, 'hard+.s');
B. WHERE REGEXP_LIKE (category_description, '^H|hard+.s');
C. WHERE REGEXP_LIKE (category_description, '^H|hard+.s$');
D. WHERE REGEXP_LIKE (category_description, '[^H|hard+.s]');
Answer: AB
正则表达式规则: [^. . .] --- A “not equals” bracket expression
| --- Logical OR.
. --- Match any character in the database character set.
$ --- End of line anchor
^ --- Beginning of line anchor.
+ ----Match one or more occurrences of the preceding subexpression.
Occurrences:正在发生的 expression:表达式
Eg:
update emp set ename='harddisks' where emp_no=5;
select * from emp where REGEXP_LIKE (ename, '^H|hard+.s');
select * from emp where REGEXP_LIKE (ename, 'H|hard+.s');
select * from emp where REGEXP_LIKE (ename, 'hard+.s');
可以查出数据
select * from emp where REGEXP_LIKE (ename, 'H|hard+.s$');
无任何数据
109. Which two statements are true regarding roles? (Choose two.)
A. A role can be granted to itself.
B. A role can be granted to PUBLIC.
C. A user can be granted only one role at any point of time.
D. The REVOKE command can be used to remove privileges but not roles from
other users.
E. Roles are named groups of related privileges that can be granted to users
or other roles.
Answer: BE
SQL> create role r1;
角色已创建。
SQL> grant create session to r1;
授权成功。
SQL> grant r1 to public;
授权成功。
SQL> grant r1 to r1;
grant r1 to r1
第 1 行出现错误:
ORA-01934: 检测到循环的角色授权
1) Roles are named groups of related privileges that you grant to users or other
roles.Roles are designed to ease the administration of end-user system and schema object
privileges.However, roles are not meant to used for application developers, because
the privileges to access schema objects within stored programmatic constructs need to
be granted directly.(Roles主要用于方便权限管理,后半句什么意思呢?什么情况下的权限需
要直接授予呢?存储过程,触发器)
2) The DBA can create a role with a password to prevent unauthorized use of the privileges
granted to the role.(角色可以加密)
3) Roles are not contained in any schema. Therefore, a user who creates a role can be
dropped with no effect on the role.(角色不属于任何用户schema,谁可以建角色呢? with
create role权限)
2 who can grant or revoke roles
1) Any user with the GRANT ANY ROLE system privilege can grant or revoke any role
except a global role to or from other users or roles of the database.
2) Any user granted a role with the ADMIN OPTION can grant or revoke that role to
or from other users or roles of the database.
3 DDL statements and Roles
Oracle avoids the dependencies on privileges received by way of roles by restricting
the use of specific privileges in certain DDL statements, The following rules outline
these privilege restrictions concerning DDL statements:
1) All system privileges and schema object privileges that permit a user to perform.
a DDL operation are usable when received through a role.(通过角色得到的DDL权限在DDL
操作中是可用的,即create view等可以)
2) All system privileges and object privileges that allow a user to perform. a DML
operation that is required to issuse a DDL statement are not usable when received through
a role.(通过角色得到的DML权限在DDL操作中不可用, 即select,insert等不可以)
DDL全称“数据库模式定义语言(Data Description Language)”;
DML全称“数据库操作语言(Data Manipulation Language)”。
110. View the Exhibit and examine the data in the CUST_DET table.
You executed the following multitable INSERT statement:
INSERT FIRST WHEN credit_limit >= 5000 THEN
INTO cust_1 VALUES(cust_id, credit_limit, grade, gender)
WHEN grade = THEN
INTO cust_2 VALUES(cust_id, credit_limit, grade, gender)
WHEN grade = THEN
INTO cust_3 VALUES(cust_id, credit_limit, grade, gender)
INTO cust_4 VALUES(cust_id, credit_limit, grade, gender)
ELSE
INTO cust_5 VALUES(cust_id, credit_limit, grade, gender)
SELECT * FROM cust_det;
The row will be inserted in _______.
A. CUST_1 table only because CREDIT_LIMIT condition is satisfied
B. CUST_1 and CUST_2 tables because CREDIT_LIMIT and GRADE conditions are
satisfied
C. CUST_1,CUST_2 and CUST_5 tables because CREDIT_LIMIT and GRADE conditions
are satisfied
but GENDER condition is not satisfied
D. CUST_1, CUST_2 and CUST_4 tables because CREDIT_LIMIT and GRADE conditions
are satisfied
for CUST_1 and CUST_2, and CUST_4 has no condition on it
Answer: A
Satisfied:满意的
111. View the Exhibit and examine the data in the EMPLOYEES tables.
Evaluate the following SQL statement:
SELECT employee_id, department_id
FROM employees WHERE department_id= 50 ORDER BY department_id
UNION
SELECT employee_id, department_id FROM employees WHERE department_id= 90
UNION
SELECT employee_id, department_id FROM employees WHERE department_id= 10;
What would be the outcome of the above SQL statement?
A. The statement would execute successfully and display all the rows in the
ascending order of DEPARTMENT_ID.
B. The statement would execute successfully but it will ignore the ORDER BY
clause and display the rows in random order.
C. The statement would not execute because the positional notation instead
of the column name should be used with the ORDER BY clause.
D. The statement would not execute because the ORDER BY clause should appear
only at the end of the SQL statement, that is, in the last SELECT statement.
Answer: D
1: SQL> select emp_no,ename from emp
where emp_no=1
order by emp_no
union
select emp_no,ename from emp
where emp_no=3;
第 4 行出现错误:
ORA-00933: SQL 命令未正确结束
2: SQL> select emp_no,ename from emp
where emp_no=1
union
select emp_no,ename from emp
where emp_no=3
order by emp_no;
112. View the Exhibit and examine the details of the EMPLOYEES table.
Evaluate the following SQL statements:
Statement 1:
SELECT employee_id, last_name, job_id, manager_id
FROM employees START WITH employee_id = 101
CONNECT BY PRIOR employee_id = manager_id AND manager_id != 108 ;
Statement 2:
SELECT employee_id, last_name, job_id, manager_id
FROM employees WHERE manager_id != 108 START WITH employee_id = 101
CONNECT BY PRIOR employee_id = manager_id;
Which two statements are true regarding the above SQL statements? (Choose
two.)
A. Statement 2 would not execute because the WHERE clause condition is not
allowed in a statement that has the START WITH clause.
B. The output for statement 1 would display the employee with MANAGER_ID 108
and all the employees below him or her in the hierarchy.
C. The output of statement 1 would neither display the employee with
MANAGER_ID 108 nor any employee below him or her in the hierarchy.
D. The output for statement 2 would not display the employee with MANAGER_ID
108 but it would display all the employees below him or her in the hierarchy.
Answer: CD
DEPTID PAREDEPTID NAME
NUMBER NUMBER CHAR (40 Byte)
部门id 父部门id(所属部门id) 部门名称
通过子节点向根节点追朔.
Sql代码 select * from dept start with deptid=76 connect by prior paredeptid=deptid
通过根节点遍历子节点.
Sql代码
select * from dept start with paredeptid=0 connect by prior deptid=paredeptid
可通过level 关键字查询所在层次.
Sql代码
select a.*,level from persons.dept a start with paredeptid=0 connect by prior dept
id=paredeptid
再次复习一下:start with ...connect by 的用法, start with 后面所跟的就是就是递归的
种子。 递归的种子也就是递归开始的地方 connect by 后面的"prior" 如果缺省:则只能查询
到符合条件的起始行,并不进行递归查询;
connect by prior 后面所放的字段是有关系的,它指明了查询的方向。
PRIORY运算符必须放置在连接关系的两列中某一个的前面。对于节点间的父子关系,PRIOR
运算符在一侧表示父节点,在另一侧表示子节点,从而确定查找树结构是的顺序是自顶向下还
是自底向上。
SQL> select * from dept;
DEPTID PAREDEPTID NAME
---------- ---------- ----------
1 0 tt
2 1 tt
3 2 tt
4 2 tt
5 3 tt
SQL> select * from dept start with deptid=3 connect by prior deptid=paredeptid;
DEPTID PAREDEPTID NAME
---------- ---------- ----------
3 2 tt
5 3 tt
SQL> select * from dept start with deptid=3 connect by prior paredeptid=deptid;
DEPTID PAREDEPTID NAME
---------- ---------- ----------
3 2 tt
2 1 tt
1 0 tt
SQL> select * from dept where paredeptid !=2 start with deptid=3
connect by prior paredeptid=deptid ;
DEPTID PAREDEPTID NAME
---------- ---------- ----------
2 1 tt
1 0 tt
SQL> select * from dept start with deptid=3
connect by prior paredeptid=deptid where paredeptid !=2;
ORA-00933: SQL 命令未正确结束
(没看明白)
113. Evaluate the SQL statements:
CREATE TABLE new_order
(orderno NUMBER(4),
booking_date TIMESTAMP WITH LOCAL TIME ZONE);
The database is located in San Francisco where the time zone is -8:00.
The user is located in New York where the time zone is -5:00.
A New York user inserts the following record:
INSERT INTO new_order VALUES(1, TIMESTAMP ‘2007-05-10 6:00:00 -5:00’);
Which statement is true?
A. When the New York user selects the row, booking_date is displayed as
'007-05-10 3.00.00.000000'
B. When the New York user selects the row, booking_date is displayed as
'2007-05-10 6.00.00.000000 -5:00'.
C. When the San Francisco user selects the row, booking_date is displayed
as '2007-05-10 3.00.00.000000'
D. When the San Francisco user selects the row, booking_date is displayed
as '2007-05-10 3.00.00.000000 -8:00'
Answer: C
查看数据库时区信息:
SQL> select dbtimezone from dual;
查看session时区信息:
SQL> select sessiontimezone from dual;
DATE:存储日期和时间信息,精确到秒。
SQL> alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
Session altered.
SQL> select to_date('2009-01-12 13:24:33','YYYY-MM-DD HH24:MI:SS') from dual;
TO_DATE('2009-01-12
-------------------
2009-01-12 13:24:33
TIMESTAMP:DATE类型的扩展,保留小数级别的秒,默认为小数点后6位。不保存时区和地区信息。
SQL> select localtimestamp from dual;
LOCALTIMESTAMP
---------------------------------------------------------------------------
12-JAN-09 07.21.37.984000 PM
TIMESTAMP WITH TIME ZONE:存储带时区信息的TIMESTAMP(以和UTC时间差或者地区信息的形式保存)。形式大
致为:
TIMESTAMP '2009-01-12 8:00:00 +8:00'
TIMESTAMP WITH LOCAL TIME ZONE:另一种不同类型的TIMESTAMP,和TIMESTAMP WITH TIME ZONE类型的区别在
于:数据库不保存时区相关信息,而是把客户端输入的时间转换为基于database timezone的时间后存入数据库
(这也就是database tmiezone设置的意义所在,作为TIMESTAMP WITH LOCAL TIME ZONE类型的计算标尺)。当用
户请求此类型信息时,Oracle把数据转换为用户session的时区时间返回给用户。所以Oracle建议把database
timezone设置为标准时间UTC,这样可以节省每次转换所需要的开销,提高性能。
操作TIMESTAMP WITH LOCAL TIME ZONE数据类型:
SQL> ALTER SESSION SET TIME_ZONE='-07:00';
SQL> CREATE TABLE table_tsltz (c_id NUMBER, c_tsltz TIMESTAMP WITH LOCAL TIME ZONE);
SQL> INSERT INTO table_tsltz VALUES(1, '01-JAN-2009 2:00:00');
SQL> INSERT INTO table_tsltz VALUES(2, TIMESTAMP '2009-01-01 2:00:00');
SQL> INSERT INTO table_tsltz VALUES(3, TIMESTAMP '2009-01-01 2:00:00 -08:00');
SQL> commit;
SQL> select * from table_tsltz;
---------------------------------------------------------------------------
1 01-JAN-09 02:00:00.000000
2 01-JAN-09 02:00:00.000000
3 01-JAN-09 03:00:00.000000
Note:插入的第三条数据指定为UTC-8时区的时间,然后存入数据库后按照database timezone的时间保存,最后
在客户端请求的时候,转换为客户端时区的时间(UTC-7)返回!可以参考以下简单实验:
SQL> ALTER SESSION SET TIME_ZONE='-05:00';
SQL> select * from table_tsltz;
---------------------------------------------------------------------------
1 01-JAN-09 04:00:00.000000
2 01-JAN-09 04:00:00.000000
3 01-JAN-09 05:00:00.000000
可以看出,当客户端时区改为UTC-5的时候,TIMESTAMP WITH LOCAL TIME ZONE数据类型的返回信息是会相
应改变的。
在了解了相关数据类型后,那么我们该如何在它们之间做出选择呢?
当你不需要保存时区/地区信息的时候,选择使用TIMESTAMP数据类型,因为它一般需要7-11bytes的存储空
间,可以节省空间。
当你需要保存时区/地区信息的时候,请选择使用TIMESTAMP WITH TIME ZONE数据类型。比如一个跨国银行
业务应用系统,需要精确纪录每一笔交易的时间和地点(时区),在这种情况下就需要纪录时区相关信息。因为
需要纪录时区相关信息,所以需要多一些的存储空间,一般需要13bytes。
当你并不关心操作发生的具体地点,而只是关心操作是在你当前时区的几点发生的时候,选择使用
TIMESTAMP WITH LOCAL TIME ZONE。比如一个全球统一的change control system。用户可能只关心某某操作是
在我的时间几点发生的(比如中国用户看到的是北京时间8:00am,而伦敦的用户看到的是0:00am)。记住,此类
行不保存时区/地区信息,因此如果需要保存相关信息的要慎重!
114. Which statements are true? (Choose all that apply.)
A. The data dictionary is created and maintained by the database
administrator.
B. The data dictionary views can consist of joins of dictionary base tables
and user defined tables.
C. The usernames of all the users including the database administrators are
stored in the data dictionary.
D. The USER_CONS_COLUMNS view should be queried to find the names of the
columns to which a constraint applies.
E. Both USER_OBJECTS and CAT views provide the same information about all
the objects that are owned by the user.
F. Views with the same name but different prefixes, such as DBA, ALL and USER,
use the same base tables from the data dictionary
Answer: CDF
对应C的疑问: select * from v$pwfile_users; 目前只有sys用户,口令
oracle 超级用户口令放在文件里 ,好恢复 PWDosid.ora 可以删除的
非超级用户口令全部在数据库里(只有open时才能连接)
sql server sa不是用户,是个登陆,里面有dbo用户 ,只是绑定了
保持在master里面 (只要master不坏,就可以恢复别的数据库)
对应E的解释:
There are only two columns in USER_CATALOG: TABLE_TYPE and TABLE_
NAME, where TABLE_NAME is actually the name of the table, view, sequence, or synonym
object.A synonym for USER_CATALOG is CAT.
The USER_OBJECTS view contains information about all objects owned by the user(包括
存储过程等). A synonym for USER_OBJECTS is OBJ.
The data dictionary is a collection of database tables and views. It is automatically
built and populated by the Oracle database. The information stored in the data
dictionary includes the full description of all the database objects you create as part
of your application: tables, views, indexes, constraints, synonyms, sequences, and
more.
115. View the Exhibit and examine the details of the PRODUCT_INFORMATION
table.You have the requirement to display PRODUCT_NAME and LIST_PRICE from
the table where the CATEGORY_ID column has values 12 or 13, and the
SUPPLIER_ID column has the value 102088. You executed the following SQL
statement: SELECT product_name, list_price FROM product_information
WHERE (category_id = 12 AND category_id = 13) AND supplier_id = 102088;
Which statement is true regarding the execution of the query?
A. It would execute but the output would return no rows.
B. It would execute and the output would display the desired result.
C. It would not execute because the entire WHERE clause condition is not
enclosed within the parentheses.
D. It would not execute because the same column has been used in both sides
of the AND logical operator to form the condition.
Answer: A
AND 应该换为or
116. Given below is the list of meta character syntaxes and their descriptions
in random order:Meta character syntax Description
1) ^ a) Matches character not in the list
2) [^...] b) Matches character when it occurs at the beginning of a line
3) | c) Treats the subsequent meta character as a literal
4) \ d) Matches one of the characters such as the OR operator
Identify the option that correctly matches the meta character syntaxes with
their descriptions.
A. 1b,2a,3d,4c
B. 1a,2b,3d,4c
C. 1d,2b,3a,4c
D. 1b,2c,3d,2a
Answer: A
Literal 文字的
117. View the Exhibit and examine the structure of ORDERS and CUSTOMERS
tables.Evaluate the following UPDATE statement:
UPDATE (SELECT order_date, order_total, customer_id FROM orders)SET
order_date = '22mar2007' WHERE customer_id =(SELECT customer_id
FROM customers WHERE cust_last_name = 'Roberts' AND credit_limit = 600);
Which statement is true regarding the execution of the above UPDATE
statement?
A. It would not execute because two tables cannot be used in a single UPDATE
statement.
B. It would execute and restrict modifications to only the columns specified
in the SELECT statement.
C. It would not execute because a subquery cannot be used in the WHERE clause
of an UPDATE statement.
D.It would not execute because the SELECT statement cannot be used in place
of the table name.
Answer: B
Restrict:限制
118. Which statement correctly differentiates a system privilege from an
object privilege?
A. System privileges can be granted only by the DBA where as object privileges
can be granted by DBAs or the owner of the object.
B. System privileges give the rights to only create user schemas where as
object privileges give rights to manipulate objects in a schema.
C. Users require system privileges to gain access to the database where as
they require object privileges to create objects in the database.
D. A system privilege is the right to perform specific activities in a
database where as an object privilege is a right to perform activities on
a specific object in the database.
Answer: D
System privilege:The ability to perform a particular task in the database
Object privilege:The ability to perform a particular task on a particular
database object
Particular:特别
119. View the Exhibit and examine the data in the PRODUCT_INFORMATION table.
Which two tasks would require subqueries? (Choose two.)
A. displaying the minimum list price for each product status
B. displaying all supplier IDs whose average list price is more than 500
C. displaying the number of products whose list prices are more than the
average list price
D. displaying all the products whose minimum list prices are more than the
average list price of products having the product status orderable
E. displaying the total number of products supplied by supplier 102071 and
having product status OBSOLETE
Answer: CD
快速定位,需要跟平均值比较,要子查询的,B容易干扰判断
120. Which two statements are true regarding constraints? (Choose two.)
A. A foreign key cannot contain NULL values.
B. A column with the UNIQUE constraint can contain NULL.
C. A constraint is enforced only for the INSERT operation on a table.
D. A constraint can be disabled even if the constraint column contains data.
E. All the constraints can be defined at the column level as well as the table
level.
Answer: BD
结论:有外键约束的字段可以为空。如果不为空的话,则一定要满足外键的约束关系, 组合外
键中有列为空,Oracle不再检查其他列是否满足外键约束的条件,而使得这条记录直接插入到
子表中。
SQL> create table t_p (id number, name varchar2(30), constraint pk_t_p primary k
ey (id, name));
SQL> create table t_c (id number, f_id number, f_name varchar2(30),
constraint fk_t_c foreign key (f_id, f_name) references t_p);
SQL> insert into t_p values (1, 'a');
SQL> insert into t_c values (1, 1, 'a');
SQL> insert into t_c values (1, 1, 'b');
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.FK_T_C) violated - parent key not found
SQL> insert into t_c values (1, null, 'b');
SQL> insert into t_c values (1, null, 'b');
SQL> select * from t_c;
1 1 a
1 b
1 b
Primary key 与Unique Key都是唯一性约束。但二者有很大的区别:
1、Primary key的1个或多个列必须为NOT NULL,如果列为NULL,在增加PRIMARY KEY时,列自
动更改为NOT NULL。而UNIQUE KEY 对列没有此要求。
2、一个表只能有一个PRIMARY KEY,但可以有多个UNIQUE KEY。
SQL> create table t (a int,b int,c int,d int);
SQL> desc t
Name Null? Type
----------------------------------------- -------- -----------
A NUMBER(38)
B NUMBER(38)
C NUMBER(38)
D NUMBER(38)
SQL> alter table t add constraint pk_t primary key (a,b);
SQL> desc t
Name Null? Type
----------------------------------------- -------- ----------------
A NOT NULL NUMBER(38)
B NOT NULL NUMBER(38)
C NUMBER(38)
D NUMBER(38)
可以看到A、B两个列都自动改为了NOT NULL
SQL> alter table t modify (a int null); *
ERROR at line 1:
ORA-01451: column to be modified to NULL cannot be modified to NULL
可以看到,列A不允许改为NULL
SQL> alter table t drop constraint pk_t;
SQL> alter table t add constraint uk_t_1 unique (a,b);
SQL> desc t
Name Null? Type
-----------------------------------------
A NUMBER(38)
B NUMBER(38)
C NUMBER(38)
D NUMBER(38)
我们看到列A又变回了NULL。
注意到,在删除主键时,列的NULLABLE会回到原来的状态。如果在创建主键后,对原来为NULL
的主键列,显式设为NOT NULL,在删除主键后仍然是NOT NULL。比如在创建主键后,执行下面
的操作,可以看到:
SQL> alter table t modify (b int not null);
SQL> alter table t drop constraint pk_t;
SQL> desc t
A NUMBER(38)
B NOT NULL NUMBER(38)
C NUMBER(38)
D NUMBER(38)
再做如下的实验:
SQL> drop table t;
SQL> create table t (a int,b int,c int,d int);
SQL> alter table t add constraint uk_t_1 unique (a,b);
SQL> alter table t add constraint uk_t_2 unique (c,d);
可以看到可以增加两个UNIQUE KEY。看看能不能增加两个主键:
SQL> alter table t add constraint pk_t primary key (c);
Table altered.
SQL> alter table t add constraint pk1_t primary key (d);
ORA-02260: table can have only one primary key
由此可以看到一个表只能有一个主键。
SQL> alter table t drop constraint pk_t;
SQL> insert into t (a ,b ) values (null,null);
SQL> /
1 row created.(可以重复插入都为null的值)
SQL> insert into t (a ,b ) values (null,1);
1 row created.
SQL> /
ERROR at line 1:
ORA-00001: unique constraint (SYS.UK_T_1) violated
SQL> insert into t (a ,b ) values (1,null);
1 row created.
SQL> /
insert into t (a ,b ) values (1,null)
ORA-00001: unique constraint (SYS.UK_T_1) violated
主键和唯一键约束是通过参考索引实施的,如果插入的值均为NULL,则根据索引的原理,全NULL
值不被记录在索引上,所以插入全NULL值时,可以有重复的,而其他的则不能插入重复值。
121. View the Exhibit and examine the description of the ORDER_ITEMS table.
The following SQL statement was written to retrieve the rows for the
PRODUCT_ID that has a UNIT_PRICE of more than 1,000 and has been ordered more
than five times:
SELECT product_id, COUNT(order_id) total, unit_price FROM order_items
WHERE unit_price>1000 AND COUNT(order_id)>5 GROUP BY product_id, unit_price;
Which statement is true regarding this SQL statement?
A. The statement would execute and give you the desired result.
B. The statement would not execute because the aggregate function is used
in the WHERE clause.
C. The statement would not execute because the WHERE clause should have the
OR logical operator instead of AND.
D. The statement would not execute because in the SELECT clause, the
UNIT_PRICE column is placed after the column having the aggregate function.
Answer: B
122. Which two statements best describe the benefits of using the WITH clause?
(Choose two.)
A. It enables users to store the results of a query permanently.
B. It enables users to store the query block permanently in the memory and
use it to create complex queries.
C. It enables users to reuse the same query block in a SELECT statement, if
it occurs more than once in a complex query.
D. It can improve the performance of a large query by storing the result of
a query block having the WITH clause in the user's temporary tablespace.
Answer: CD
Benefits:好处 permanently 永久的
You can use the keyword WITH to assign a name to a subquery block. Once
the name is assigned, you can reference the name from elsewhere in the query.
123. View the Exhibit and examine the structure of the ORDERS and ORDER_ITEMS
tables.In the ORDERS table, ORDER_ID is the PRIMARY KEY and ORDER_DATE has
the DEFAULT value as SYSDATE.Evaluate the following statement:
UPDATE orders SET order_date=DEFAULT
WHERE order_id IN (SELECT order_id FROM order_items WHERE qty IS NULL);
What would be the outcome of the above statement?
A. The UPDATE statement would not work because the main query and the subquery
use different tables.
B. The UPDATE statement would not work because the DEFAULT value can be used
only in INSERT statements.
C. The UPDATE statement would change all ORDER_DATE values to SYSDATE
provided the current ORDER_DATE is NOT NULL and QTY is NULL.
D. The UPDATE statement would change all the ORDER_DATE values to SYSDATE
irrespective of what the current ORDER_DATE value is for all orders where
QTY is NULL.
Answer: D
Irrespective:不考虑
SQL> create table tt(a date default sysdate);
SQL> insert into tt values(sysdate);
SQL> insert into tt values(to_date('2004-05-07 13:23:44','yyyy-mm-dd
hh24:mi:ss'));
SQL> update tt set a=default;
124. View the Exhibit and examine the description of the EMPLOYEES table.
Evaluate the following SQL statement:
SELECT employee_id, last_name, job_id, manager_id, LEVEL
FROM employees START WITH employee_id = 101
CONNECT BY PRIOR employee_id=manager_id ;
Which two statements are true regarding the output of this command? (Choose
two.)
A. The output would be in top-down hierarchy starting with EMPLOYEE_ID having
value 101.
B. The output would be in bottom-up hierarchy starting with EMPLOYEE_ID
having value 101.
C. The LEVEL column displays the number of employees in the hierarchy under
the employee having the EMPLOYEE_ID 101.
D. The LEVEL column displays the level in the hierarchy at which the employee
is placed under the employee having the EMPLOYEE_ID 101.
Answer: AD
Topdown: 由上至下bottomup: 由下至上
做题的时候要仔细,LEVEL 是显示层次的
125. Which three statements are true regarding the WHERE and HAVING clauses
in a SQL statement?
(Choose three.)
A. The HAVING clause conditions can have aggregate functions.
B. The HAVING clause conditions can use aliases for the columns.
C. WHERE and HAVING clauses cannot be used together in a SQL statement.
D. The WHERE clause is used to exclude rows before the grouping of data.
E. The HAVING clause is used to exclude one or more aggregated results after
grouping data.
Answer: ADE
Aggregate:合计
Having不能用别名
SQL> select a tt,sum(b) from test group by a having tt<2;
ORA-00904: "TT": 标识符无效
SQL> select a tt,sum(b) from test group by a having sum(a)<2;
ok
127. Which statements are true regarding the usage of the WITH clause in
complex correlated subqueries?
(Choose all that apply.)
A. It can be used only with the SELECT clause.
B. The WITH clause can hold more than one query.
C. If the query block name and the table name were the same, then the table
name would take precedence.
D. The query name in the WITH clause is visible to other query blocks in the
WITH clause as well as to the main query block.
Answer: ABD
Precedence:优先
1: SQL> with
2 tt as(
3 select emp_no,enam
4 from emp
5 where mgr_no=4)
6 select ename
7 from tt
8 where emp_no=4;
Ok!
2: SQL> with
2 emp as(
3 select emp_no,ename
4 from emp
5 where mgr_no=4)
6 select ename
7 from emp
8 where emp_no=4;
ORA-32031: WITH 子句中查询名的引用非法
128. Evaluate the following SQL statement:
CREATE INDEX upper_name_idx ON product_information(UPPER(product_name));
Which query would use the UPPER_NAME_IDX index?
A. SELECT UPPER(product_name) FROM product_information
WHERE product_id = 2254;
B. SELECT UPPER(product_name)
FROM product_information;
C. SELECT product_id FROM product_information
WHERE UPPER(product_name) IN ('LASERPRO', 'Cable');
D. SELECT product_id, UPPER(product_name)
FROM product_information WHERE UPPER(product_name)='LASERPRO' OR
list_price > 1000;
Answer: C
129. Which three statements are true regarding group functions? (Choose
three.)
A. They can be used on columns or expressions.
B. They can be passed as an argument to another group function.
C. They can be used only with a SQL statement that has the GROUP BY clause.
D. They can be used on only one column in the SELECT clause of a SQL statement.
E. They can be used along with the single-row function in the SELECT clause
of a SQL statement.
Answer: ABE
Argument:意见 along with:连同..一起
single-row function指一行数据输入,返回一个值的函数。
如substr等。
而mutil-row function指多行数据输入,返回一个值的函数。
如sum、max等。
Eg: SQL> select a,a+b ,sum(b) from test group by a,a+b;
ok
对应E选项是说的可以用
130. Which three statements are true regarding single-row functions? (Choose
three.)
A. They can accept only one argument.
B. They can be nested up to only two levels.
C. They can return multiple values of more than one data type.
D. They can be used in SELECT, WHERE, and ORDER BY clauses.
E. They can modify the data type of the argument that is referenced.
F. They can accept a column name, expression, variable name, or a usersupplied
constant as arguments.
Answer: DEF
Constant:不变的 reference:提及
single-row function指一行数据输入,返回一个值的函数。 如substr等。
而mutil-row function指多行数据输入,返回一个值的函数。 如sum、max等。
ocp 1Z0-047 61-130题解析的更多相关文章
- 【12c OCP】CUUG OCP认证071考试原题解析(36)
36.choose the best answer View the Exhibits and examine the structures of the PRODUCTS, SALES, and C ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(35)
35.choose the best answer View the Exhibit and examine the description of the EMPLOYEES table. Evalu ...
- 【12c OCP】CUUG OCP认证071考试原题解析(34)
34.choose two View the Exhibit and examine the structure of the PRODUCT_INFORMATION and INVENTORIES ...
- 【12c OCP】CUUG OCP认证071考试原题解析(33)
33.choose the best answer View the Exhibit and examine the structure of the ORDER_ITEMS table. Exami ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(32)
32.choose the best answer View the Exhibit and examine the data in EMP and DEPT tables. In the DEPT ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(31)
31.choose the best answer Which statement is true regarding the USING clause in table joins? A) It c ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(30)
30.choose the best answer Examine the commands used to create DEPARTMENT_DETAILS and COURSE_DETAILS: ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(29)
29.choose the best answer Evaluate the following query: SQL> SELECT promo_name || q'{'s start dat ...
- 啤酒和饮料|2014年蓝桥杯B组题解析第一题-fishers
啤酒和饮料|2014年第五届蓝桥杯B组题解析第一题-fishers 啤酒和饮料 啤酒每罐2.3元,饮料每罐1.9元.小明买了若干啤酒和饮料,一共花了82.3元. 我们还知道他买的啤酒比饮料的数量少,请 ...
- JS-常考算法题解析
常考算法题解析 这一章节依托于上一章节的内容,毕竟了解了数据结构我们才能写出更好的算法. 对于大部分公司的面试来说,排序的内容已经足以应付了,由此为了更好的符合大众需求,排序的内容是最多的.当然如果你 ...
随机推荐
- BZOJ 2326 数学作业(矩阵)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2326 题意:定义Concatenate(1,N)=1234567……n.比如Concat ...
- UVa 11992 (线段树 区间修改) Fast Matrix Operations
比较综合的一道题目. 二维的线段树,支持区间的add和set操作,然后询问子矩阵的sum,min,max 写完这道题也是醉醉哒,代码仓库里还有一份代码就是在query的过程中也pushdown向下传递 ...
- busybox filesystem httpd php-5.5.31 sqlite3 webserver
/******************************************************************** * busybox filesystem httpd php ...
- [转](多实例)mysql-mmm集群
一.需求说明 最近一直在学习mysql-mmm,想以后这个架构也能用在我们公司的业务上,我们公司的业务是单机多实例部署,所以也想把mysql-mmm部署成这样,功夫不负有心人,我成功了,和大家分享一下 ...
- Android精美的日历控件
网上看到的精美日历控件,谨以此文记录一下,用到的时候再来翻翻 源码地址 : http://download.csdn.net/detail/abc13939746593/7265459
- 【RMQ问题】求数组区间最大值,NYOJ-1185-最大最小值
转自:http://blog.csdn.net/lilongherolilong/article/details/6624390 先挖好坑,明天该去郑轻找虐 RMQ(Range Minimum/Max ...
- [android]如何让TextView使用超链接
找了很多网址,最后是这个有说到. 总的做法是: 1.(当然也可以从Res中获取.) tv.setText(Html.fromHtml("<a href=\"http://ww ...
- hdu 3342 Legal or Not(拓扑排序) HDOJ Monthly Contest – 2010.03.06
一道极其水的拓扑排序……但是我还是要把它发出来,原因很简单,连错12次…… 题意也很裸,前面的废话不用看,直接看输入 输入n, m表示从0到n-1共n个人,有m组关系 截下来m组,每组输入a, b表示 ...
- Java SE 6 新特性: 对脚本语言的支持
2006 年底,Sun 公司发布了 Java Standard Edition 6(Java SE 6)的最终正式版,代号 Mustang(野马).跟 Tiger(Java SE 5)相比,Musta ...
- Jedis的JedisSentinelPool源代码分析
概述 Jedis是Redis官方推荐的Java客户端,更多Redis的客户端可以参考Redis官网客户端列表.Redis-Sentinel作为官方推荐的HA解决方案,Jedis也在客户端角度实现了对S ...