1. View the Exhibit and examine the structure of the SALES, CUSTOMERS, PRODUCTS, and TIMES
tables.
The PROD_ID column is the foreign key in the SALES table, which references the PRODUCTS table.
Similarly, the CUST_ID and TIME_ID columns are also foreign keys in the SALES table referencing the
CUSTOMERS and TIMES tables, respectively.
Evaluate the following CREATE TABLE command:
CREATE TABLE new_sales(prod_id, cust_id, order_date DEFAULT SYSDATE)
AS
SELECT prod_id, cust_id, time_id
FROM sales;
Which statement is true regarding the above command?
A. The NEW_SALES table would not get created because the DEFAULT value cannot be specified in the
column definition.
B. The NEW_SALES table would get created and all the NOT NULL constraints defined on the specified
columns would be passed to the new table.
C. The NEW_SALES table would not get created because the column names in the CREATE TABLE
command and the SELECT clause do not match.
D. The NEW_SALES table would get created and all the FOREIGN KEY constraints defined on the
specified columns would be passed to the new table.
Answer: B
解析:git
SQL> create table SALES(prod_id number not null,cust_id number not null,time_id date not null,channel_id number not null,promo_id number not null,quantity_sold number(10,2) not null); 表已建立。 SQL> CREATE TABLE new_sales(prod_id, cust_id, order_date DEFAULT SYSDATE) AS SELECT prod_id, cust_id, time_id FROM sales; 表已建立。 SQL> DESC new_sales; 名稱 是否爲空? 類型 ----------------------------------------- -------- ---------------------------- PROD_ID NOT NULL NUMBER CUST_ID NOT NULL NUMBER ORDER_DATE NOT NULL DATE SQL> drop table new_sales; 表已刪除。 SQL> drop table SALES; 表已刪除。
能夠看出NOT NULL約束能夠傳遞給子表;sql
2. View the Exhibit to examine the description for the SALES table.
Which views can have all DML operations performed on it? (Choose all that apply.)
A. CREATE VIEW v3
AS SELECT * FROM SALES
WHERE cust_id = 2034
WITH CHECK OPTION;
B. CREATE VIEW v1
AS SELECT * FROM SALES
WHERE time_id <= SYSDATE - 2*365
WITH CHECK OPTION;
C. CREATE VIEW v2
AS SELECT prod_id, cust_id, time_id FROM SALES
WHERE time_id <= SYSDATE - 2*365
WITH CHECK OPTION;
D. CREATE VIEW v4
AS SELECT prod_id, cust_id, SUM(quantity_sold) FROM SALES
WHERE time_id <= SYSDATE - 2*365
GROUP BY prod_id, cust_id
WITH CHECK OPTION;
Answer: AB
解析:
注意本地題幹:Which views can have all DML operations performed on it?express
SQL> create table SALES(prod_id number not null,CUST_ID number not null,time_id date not null,channel_id number not null,promo_id number not null,quantity number(10,2) not null);
SQL> CREATE VIEW v3 AS SELECT * FROM SALES WHERE cust_id=2034 WITH CHECK OPTION;app
View created.ide
SQL> CREATE VIEW v1 AS SELECT * FROM SALES WHERE time_id<=SYSDATE - 2*365 WITH CHECK OPTION;函數
View created.
ui
C答案其餘列不能爲空
D答案sum(quantity_sold)後面須要加別名
SQL> create view v4 as select prod_id,cust_id,sum(quantity_SOLD) sumqty from sales where time_id<=sysdate-2*365 group by prod_id,cust_id with check option;this
View created.lua
3. You need to extract details of those products in the SALES table where the PROD_ID column
contains the string '_D123'.
Which WHERE clause could be used in the SELECT statement to get the required output?
A. WHERE prod_id LIKE '%_D123%' ESCAPE '_'
B. WHERE prod_id LIKE '%\_D123%' ESCAPE '\'
C. WHERE prod_id LIKE '%_D123%' ESCAPE '%_'
D. WHERE prod_id LIKE '%\_D123%' ESCAPE '\_'
Answer: B
答案解析:
ESCAPE子句爲指定轉譯字符,由於‘_’下滑線在LIKE子句中指的是任意一個字符,因此須要把_’下滑線進行轉譯。code
4. Which two statements are true regarding single row functions? (Choose two.)
A. They accept only a single argument.
B. They can be nested only to two levels.
C. Arguments can only be column values or constants.
D. They always return a single result row for every row of a queried table.
E. They can return a data type value different from the one that is referenced.
Answer: DE
答案解析:
A.單行函數能夠是含有兩個參數,如MONTHS_BETWEEN函數。
B.單行函數能夠被多級嵌套,因此B答案錯誤。
C.參數也能夠是變量或者表達式,因此C錯誤
D.單行函數只返回單一值
E. 返回的數據類型值能夠與以前引用的數據類型不一樣,因此正確。
5. Which SQL statements would display the value 1890.55 as $1,890.55? (Choose three .)
A. SELECT TO_CHAR(1890.55,'$0G000D00') FROM DUAL;
B. SELECT TO_CHAR(1890.55,'$9,999V99') FROM DUAL;
C. SELECT TO_CHAR(1890.55,'$99,999D99') FROM DUAL;
D. SELECT TO_CHAR(1890.55,'$99G999D00') FROM DUAL;
E. SELECT TO_CHAR(1890.55,'$99G999D99') FROM DUAL;
Answer: ADE
答案解析:
A:
SQL> SELECT TO_CHAR(1890.55,'$0G000D00') FROM DUAL;
TO_CHAR(18
----------
$1,890.55
B:
SQL> SELECT TO_CHAR(1890.55,'$9,999V99') FROM DUAL;
TO_CHAR(1
---------
$1,89055
C:
SQL> SELECT TO_CHAR(1890.55,'$99,999D99') FROM DUAL;
SELECT TO_CHAR(1890.55,'$99,999D99') FROM DUAL
*
ERROR at line 1:
ORA-01481: invalid number format model
D:
SQL> SELECT TO_CHAR(1890.55,'$99G999D00') FROM DUAL;
TO_CHAR(189
-----------
$1,890.55
E:
SQL> SELECT TO_CHAR(1890.55,'$99G999D99') FROM DUAL;
TO_CHAR(189
-----------
$1,890.55
G表示分組分隔符group
D表示小數點decimal point
V表示移動N位(小數點),乘以10的n次方後面跟幾位就是幾回方。
","和G或者D不能同時出現,若是把C答案的D改爲「.」,也正確
SQL> SELECT TO_CHAR(1890.55,'$99,999.99') FROM DUAL;
TO_CHAR(189
-----------
$1,890.55
總之,字符和字母不能同時出現。
6. Examine the structure of the SHIPMENTS table:
name Null Type
PO_ID NOT NULL NUMBER(3)
PO_DATE NOT NULL DATE
SHIPMENT_DATE NOT NULL DATE
SHIPMENT_MODE VARCHAR2(30)
SHIPMENT_COST NUMBER(8,2)
You want to generate a report that displays the PO_ID and the penalty amount to be paid if the
SHIPMENT_DATE is later than one month from the PO_DATE. The penalty is $20 per day.
Evaluate the following two queries:
SQL> SELECT po_id, CASE
WHEN MONTHS_BETWEEN (shipment_date,po_date)>1 THENTO_CHAR((shipment_date - po_date) * 20) ELSE 'No Penalty' END PENALTY
FROM shipments;
SQL>SELECT po_id, DECODE
(MONTHS_BETWEEN (po_date,shipment_date)>1,
TO_CHAR((shipment_date - po_date) * 20), 'No Penalty') PENALTY
FROM shipments;
Which statement is true regarding the above commands?
A. Both execute successfully and give correct results.
B. Only the first query executes successfully but gives a wrong result.
C. Only the first query executes successfully and gives the correct result.
D. Only the second query executes successfully but gives a wrong result.
E. Only the second query executes successfully and gives the correct result.
Answer: C
答案解析:
顯示PO_ID和支付的罰款總金額,SHIPMENT_DATE與PO_DATE進行比較,SHIPMENT_DATE若是比PO_DATE晚一個月,則天天罰款$20。
SQL> CREATE TABLE SHIPMENTS(PO_ID NUMBER(3) NOT NULL,PO_DATE DATE NOT NULL,SHIPMENT_DATE DATE NOT NULL,SHIPMENT_MODE VARCHAR2(30),SHIPMENT_COST NUMBER(8,2));
Table created.
SQL> SELECT po_id, CASE WHEN MONTHS_BETWEEN (shipment_date,po_date)>1 THEN TO_CHAR((shipment_date - po_date) * 20) ELSE 'No Penalty' END PENALTY FROM shipments;
no rows selected
7. Which two statements are true regarding the USING and ON clauses in table joins? (Choose two.)
A. Both USING and ON clauses can be used for equijoins and nonequijoins.
B. A maximum of one pair of columns can be joined between two tables using the ON clause.
C. The ON clause can be used to join tables on columns that have different names but compatible data
types.
D. The WHERE clause can be used to apply additional conditions in SELECT statements containing the
ON or the USING clause.
Answer: CD
A. USING和ON子句能夠用於等值鏈接和非等值鏈接,USING不能用於非等值鏈接,ON能夠。
B. 使用ON子句最大隻能使用兩個列鏈接兩個表.錯誤,能夠鏈接多個列
C.ON子句用於鏈接表的列能夠是不一樣的名字,可是數據類型要兼容,正確。ON子句還能夠用於聯接同一表內或者不一樣表中具備不一樣名稱的列。
D.在包含ON或USING子句的SELECT命令中,WHERE子句能夠作爲附加的條件,正確
8. View the Exhibit and examine the structure of the CUSTOMERS table.
Which two tasks would require subqueries or joins to be executed in a single statement? (Choose two.)
A. listing of customers who do not have a credit limit and were born before 1980
B. finding the number of customers, in each city, whose marital status is 'married'
C. finding the average credit limit of male customers residing in 'Tokyo' or 'Sydney'
D. listing of those customers whose credit limit is the same as the credit limit of customers residing in thecity 'Tokyo'
E. finding the number of customers, in each city, whose credit limit is more than the average credit limit of
all the customers
Answer: DE
ABC不用子查詢就能夠查詢出,題意選擇兩個,排除ABC,選擇DE
A. 列出沒有信貸限額而且1980年之前出生的客戶。
SELECT 客戶 from 表名 where 信貸限額 is null and 出生日期>1980;
B. 查找每一個城市的已婚客戶的數量。
SELECT 城市名,COUNT(*) FROM 表名 where 客戶婚否=‘結婚’ group by 城市名;
C. 查找屬於'Tokyo'或者 'Sydney'兩個城市的男性客戶的平均信貸限額。
SELECT 城市名, AVG(信貸限額) from 表名 where 性別=‘男’ and 城市 in('Tokyo', 'Sydney') group by 城市名
D 列出與'Tokyo'城市的客戶的信貸限額相等的客戶
E. 查找每一個城市的客戶數量,這些客戶的信貸限額大於全部客戶的平均信貸限額。
9. Which statement is true regarding the INTERSECT operator?
A. It ignores NULL values.
B. Reversing the order of the intersected tables alters the result.
C. The names of columns in all SELECT statements must be identical.
D. The number of columns and data types must be identical for all SELECT statements in the query.
Answer: D
A. 它忽略空值,錯誤,不會忽略空值
B. 交換交集表的先後順序能夠改變交集結果,錯誤,不會改變結果
C. 全部SELECT查詢語句中的列的名字必須相同。錯誤,列名能夠沒必要相同
D. 對於全部SELECT查詢語句,列的數量和數據類型必須相同。
使用INTERSECT運算符能夠返回多個查詢的全部共同行。
準則
? 在查詢中使用的全部SELECT語句中,由查詢中的SELECT語句選定的列數和列的數據類型必須相同。不過,列名沒必要相同。
? 使相交的表按反方向排序不會更改結果。
? INTERSECT不會忽略NULL值。
若是選擇列表中包含有表達式或者函數,那麼必須爲表達式或函數定義列別名
一、Uinon:無重並集,並以第一列的結果進行升序排序
二、Uinon all:有重並集,不對結果集排序
三、Intersect:交集,以第一列的結果進行升序排列
四、Minus:差集,以第一列的結果進行升序排列
五、可以使用order by,必須放在最後一條select以後,當列名相同時,能夠直接用列名排序,若是不一樣能夠用位置排序,也可使用別名使其相同。
10. View the Exhibit; e xamine the structure of the PROMOTIONS table.
Each promotion has a duration of at least seven days .
Your manager has asked you to generate a report, which provides the weekly cost for each promotion
done to l date.
Which query would achieve the required result?
A. SELECT promo_name, promo_cost/promo_end_date-promo_begin_date/7
FROM promotions;
B. SELECT promo_name,(promo_cost/promo_end_date-promo_begin_date)/7
FROM promotions;
C. SELECT promo_name, promo_cost/(promo_end_date-promo_begin_date/7)
FROM promotions;
D. SELECT promo_name, promo_cost/((promo_end_date-promo_begin_date)/7)
FROM promotions;
Answer: D
問題解析:
須要提供促銷期間每週的成本。
ABC語法錯誤,故答案爲D;
11. View the Exhibit and examine the structure of the PRODUCTS table.
All products have a list price.
You issue the following command to display the total price of each product after a discount of 25% and a
tax of 15% are applied on it. Freight charges of $100 have to be applied to all the products.
SQL>SELECT prod_name, prod_list_price -(prod_list_price*(25/100))
+(prod_list_price -(prod_list_price*(25/100))*(15/100))+100
AS "TOTAL PRICE"
FROM products;
What would be the outcome if all the parenthese s are removed from the above statement?
A. It produces a syntax error.
B. The result remains unchanged.
C. The total price value would be lower than the correct value.
D. The total price value would be higher than the correct value.
Answer: B
此題的意思是去除括號後,答案是否同樣,其實這是一道數學題,去除括號後,其實同樣。
12. You need to produce a report where each customer's credit limit has been incremented by $1000. In
the output, t he customer's last name should have the heading Name and the incremented credit limit
should be labeled New Credit Limit. The column headings should have only the first letter of each word in
uppercase .
Which statement would accomplish this requirement?
A. SELECT cust_last_name Name, cust_credit_limit + 1000
"New Credit Limit"
FROM customers;
B. SELECT cust_last_name AS Name, cust_credit_limit + 1000
AS New Credit Limit
FROM customers;
C. SELECT cust_last_name AS "Name", cust_credit_limit + 1000
AS "New Credit Limit"
FROM customers;
D. SELECT INITCAP(cust_last_name) "Name", cust_credit_limit + 1000
INITCAP("NEW CREDIT LIMIT")
FROM customers;
Answer: C
列別名須要加""才能保留列別名的大小寫。
13. View the Exhibit and examine the structure of the PRODUCTS table.
You need to generate a report in the following format:
CATEGORIES
5MP Digital Photo Camera's category is Photo
Y Box's category is Electronics
Envoy Ambassador's category is Hardware
Which two queries would give the required output? (Choose two.)
A. SELECT prod_name q'''s category is ' prod_category CATEGORIES
FROM products;
B. SELECT prod_name q'['s ]'category is ' prod_category CATEGORIES
FROM products;
C. SELECT prod_name q'\'s\' ' category is ' prod_category CATEGORIES
FROM products;
D. SELECT prod_name q'<'s >' 'category is ' prod_category CATEGORIES
FROM products;
Answer: CD
另外Oracle還提供了一個Q-quote的表達式,來簡化SQL或PLSQL中字符串的表示,其格式爲q'[Camera's category is Photo]',輸出爲方括號中的原始字符串格式,其中方括號能夠更換爲其餘的任意一對特殊符號,但必須是成對出現的,不可爲q'[Camera's category is Photo|'。
如:
SQL> select q'[Camera's category is Photo]' name from dual;
NAME
--------------------------
Camera's category is Photo
SQL> select q'|Camera's category is 'Photo'|' name from dual;
NAME
----------------------------
Camera's category is 'Photo'
A:錯誤, is後面應該是兩個單引號,正確的爲
SELECT prod_name || q'''s category is ''|| prod_category CATEGORIES
FROM products;
B:錯誤,category 前面少了一個',正確的爲
SELECT prod_name || q'['s ]'||'category is '||prod_category CATEGORIES FROM products;
14. Using the CUSTOMERS table, you need to generate a report that shows 50% of each credit
amount in each income level. The report should NOT show any repeated credit amounts in each income
level.
Which query would give the required result?
A. SELECT cust_income_level, DISTINCT cust_credit_limit * 0.50
AS "50% Credit Limit"
FROM customers;
B. SELECT DISTINCT cust_income_level, DISTINCT cust_credit_limit * 0.50
AS "50% Credit Limit"
FROM customers;
C. SELECT DISTINCT cust_income_level ' ' cust_credit_limit * 0.50 AS "50% Credit Limit"
FROM customers;
D. SELECT cust_income_level ' ' cust_credit_limit * 0.50 AS "50% Credit Limit"
FROM customers;
Answer: C
1.DISTINCT只能出如今SQL的開頭。
2.每一個SQL語句只能有一個DISTINCT關鍵字。
15. View the Exhibit and examine the data in the CUSTOMERS table.
Evaluate the following query:
SQL> SELECT cust_name AS "NAME", cust_credit_limit/2 AS MIDPOINT,MIDPOINT+100 AS "MAX
LOWER LIMIT"
FROM customers;
The above query produces an error on execution.
What is the reason for the error?
A. An alias cannot be used in an expression.
B. The a lias NAME should not be enclosed with in double quotation marks .
C. The MIDPOINT+100 expression gives an error because CUST_CREDIT_LIMIT contains NULL
values.
D. The a lias MIDPOINT should be enclosed with in double quotation marks for the
CUST_CREDIT_LIMIT/2 expression .
Answer: A
AS後面須要加""