sql1-ch3 使用單列函數自訂輸出. 考古題題號 80 題: 7 、 37 140 題: 30 、 43...

22
SQL1-ch3 使使使使使使使使使使

Upload: marjorie-lyons

Post on 18-Jan-2016

313 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

SQL1-ch3使用單列函數自訂輸出

Page 2: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

考古題題號 80題: 7、 37 140題: 30、 43、 52、 84、 86、 127

Page 3: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

單列函數

Page 4: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127
Page 5: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

練習 查詢會員資料表 (employees)中,姓氏以 A或M字母開頭的會員姓名,並印出姓氏長度。

Page 6: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

日期函數 日期格式: DD-MON-RR

Page 7: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

Q30/140

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?

Page 8: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

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.

第一天為 Sunday(星期日 )

SELECT first_name, employee_id, NEXT_DAY(ADD_MONTHS (hire_date, 6), 1) "Review" FROM employees;

Page 9: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

資料型態轉換 相同資料型態才可比較

Page 10: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

10

Q37/80

View the Exhibit and examine the description of the ORDERS table. Evaluate the following

SQL statement:

SELECT order_id, customer_idFROM ordersWHERE order_date > 'June 30 2001';

Which statement is true regarding the execution of this SQL statement?

Page 11: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

11

Q37日期 (SQL1 ch3)

A. It would not execute because 'June 30 2001' in the WHERE condition is not enclosed within double quotation marks.

B. It would execute and would return ORDER_ID and CUSTOMER_ID for all records having ORDER_DATE greater than 'June 30 2001'.

C. It would not execute because 'June 30 2001' in the WHERE condition cannot be converted implicitly and needs the use of the TO_DATE conversion function for proper execution.

D. It would not execute because 'June 30 2001' in the WHERE condition cannot be converted implicitly and needs the use of the TO_CHAR conversion function for proper execution.

SELECT order_id, customer_idFROM ordersWHERE order_date > 'June 30 2001';

Page 12: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

資料型態轉換 若日期格式正確,則系統會自動轉換

格式不正確,須指定格式才能轉換 (P.3-33)

Page 13: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

13

Q7/80View the Exhibit and examine the description of the

ORDERS table. Which two WHERE clause conditions demonstrate the correct usage of conversion functions? (Choose two.)

A. WHERE order_date > TO_DATE('JUL 10 2006','MON DD YYYY')

B. WHERE TO_CHAR(order_date,'MON DD YYYY') = 'JAN 20 2003'

C. WHERE order_date > TO_CHAR(ADD_MONTHS(SYSDATE,6),'MON DD YYYY')

D. WHERE order_date IN ( TO_DATE('Oct 21 2003','Mon DD YYYY'), TO_CHAR('NOV 21 2003','Mon DD YYYY') )

Page 14: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

處理空值函數 空值即 NULL,不是 0也不是空白 不能做任何運算、加總。

Page 15: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127
Page 16: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

Q127/140Given below is a list of functions and their purpose in random order.

Function Purpose

1) NVL 2) NULLIF 3) COALESCE 4) NVL2  a) Used for evaluating NOT NULL and NULL values b) Used to return the first non- null values in a list of expressions c) Used to compare two expressions. If both are same, it returns NULL;

otherwise, it returns only the first expression. d) Used to convert NULL values to actual values

Identify the correct combination of functions and their usage.

Page 17: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

A. 1-a, 2-c, 3-b, 4-d B. 1-d, 2-c, 3-b, 4-a C. 1-b, 2-c, 3-d, 4-a D. 1-d, 2-b, 3-c, 4-a

Page 18: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

Q43/140(可略 )

View the Exhibit and examine the description of the EMPLOYEES table. You want to calculate the total remuneration(酬勞 ) for each employee. Total remuneration is the sum of the annual salary and the percentage commission earned for a year. Only a few employees earn commission. Which SQL statement would you execute to get the desired output?

A. SELECT first_name, salary,

salary*12+salary*commission_pct "Total" FROM EMPLOYEES;

Page 19: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

B. SELECT first_name, salary, (salary + NVL(commission_pct,0)*salary)*12 "Total" FROM EMPLOYEES;

C. SELECT first_name, salary, salary*12 + NVL(salary, 0)*commission_pct "Total" FROM EMPLOYEES;

D. SELECT first_name, salary, salary*12+(salary*NVL2(commission_pct, salary,salary+commission_pct))"Total" FROM EMPLOYEES;

Page 20: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

Q52/140(可略 )

View the Exhibit and examine the details of the PRODUCT_INFORMATION table. Evaluate the following SQL statement:

 SELECT TO_CHAR(list_price,'$9,999') FROM product_information;  Which two statements would be true regarding

the output for this SQL statement? (Choose two.)

Page 21: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

A. The LIST_PRICE column having value 1123.90 would be displayed as $1,124.

B. The LIST_PRICE column having value 1123.90 would be displayed as $1,123.

C. The LIST_PRICE column having value 11235.90 would be displayed as $1,123.

D. The LIST_PRICE column having value 11235.90 would be displayed as #######.

(P3-40)

SELECT TO_CHAR(list_price,'$9,999') FROM product_information;

Page 22: SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127

Q86/140

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. (P3-5)E. They return data type can be different from the data type of

the argument that is referenced. F. They can accept a column name, expression, variable name,

or a user-supplied constant as arguments.