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等。