to_date、to_char及格式化大小寫 nvl nvl2 nullif
Examine the structure of the TRANSACTIONS table:
name Null Type
TRANS_ID NOT NULL NUMBER(3)
The safer , easier way to help you pass any IT exams.
54 / 99
CUST_NAME VARCHAR2(30)
TRANS_DATE DATE
TRANS_AMT NUMBER(10,2)
You want to display the transaction date and specify whether it is a weekday or weekend.
Evaluate the following two queries:
SQL>SELECT TRANS_DATE,CASE
WHEN TRIM(TO_CHAR(trans_date,'DAY')) IN ('SATURDAY','SUNDAY') THEN 'weekend'
ELSE 'weekday'
END "Day Type"
FROM transactions;
SQL>SELECT TRANS_DATE, CASE
WHEN TO_CHAR(trans_date,'DAY') BETWEEN 'MONDAY' AND 'FRIDAY' THEN 'weekday'
ELSE 'weekend'
END "Day Type"FROM transactions;
Which statement is true regarding the above queries?
A. Both give wrong results.
B. Both give the correct result.
C. Only the first query gives the correct result.
D. Only the second query gives the correct result.
答案C
TO_CHAR是把日期或者數字轉換為字元,to_date把數字轉換成日期
SELECT to_date(SYSDATE,'hh24') FROM dual ---錯
SELECT to_date(SYSDATE,'hh24') FROM dual --對
SELECT to_char(SYSDATE,'day') FROM dual 輸出結果為小寫
SELECT to_char(SYSDATE,'DAY') FROM dual 輸出結果為大寫
星期是不能用BETWEEN取區間
SELECT to_char(t,'DAY') FROM t
WHERE to_char(t,'DAY') BETWEEN 'MONDAY' AND 'FRIDAY'
沒有結果返回
--------------------------------
name Null Type
PROMO_ID NOT NULL NUMBER(3)
PROMO_NAME VARCHAR2(30)
PROMO_START_DATE NOT NULL DATE
PROMO_END_DATE NOT NULL DATE
You want to display the list of promo names with the message 'Same Day' for promos that started and
ended on the same day.
Which query gives the correct output?
A. SELECT promo_name, NVL(NULLIF(promo_start_date, promo_end_date), 'Same Day')
FROM promos;
B. SELECT promo_name, NVL(TRUNC(promo_end_date - promo_start_date), 'Same Day')
FROM promos;
C. SELECT promo_name, NVL2(TO_CHAR(TRUNC(promo_end_date-promo_start_date)), NULL,'Same
Day')
FROM promos;
D. SELECT promo_name, DECODE((NULLIF(promo_start_date, promo_end_date)), NULL,'Same day')
FROM promos;
Answer: D
name Null Type
TRANS_ID NOT NULL NUMBER(3)
The safer , easier way to help you pass any IT exams.
54 / 99
CUST_NAME VARCHAR2(30)
TRANS_DATE DATE
TRANS_AMT NUMBER(10,2)
You want to display the transaction date and specify whether it is a weekday or weekend.
Evaluate the following two queries:
SQL>SELECT TRANS_DATE,CASE
WHEN TRIM(TO_CHAR(trans_date,'DAY')) IN ('SATURDAY','SUNDAY') THEN 'weekend'
ELSE 'weekday'
END "Day Type"
FROM transactions;
SQL>SELECT TRANS_DATE, CASE
WHEN TO_CHAR(trans_date,'DAY') BETWEEN 'MONDAY' AND 'FRIDAY' THEN 'weekday'
ELSE 'weekend'
END "Day Type"FROM transactions;
Which statement is true regarding the above queries?
A. Both give wrong results.
B. Both give the correct result.
C. Only the first query gives the correct result.
D. Only the second query gives the correct result.
答案C
TO_CHAR是把日期或者數字轉換為字元,to_date把數字轉換成日期
SELECT to_date(SYSDATE,'hh24') FROM dual ---錯
SELECT to_date(SYSDATE,'hh24') FROM dual --對
SELECT to_char(SYSDATE,'day') FROM dual 輸出結果為小寫
SELECT to_char(SYSDATE,'DAY') FROM dual 輸出結果為大寫
星期是不能用BETWEEN取區間
SELECT to_char(t,'DAY') FROM t
WHERE to_char(t,'DAY') BETWEEN 'MONDAY' AND 'FRIDAY'
沒有結果返回
--------------------------------
NVL (expr1, expr2)->expr1為NULL,返回expr2;不為NULL,返回expr1。注意兩者的型別要一致 NVL2 (expr1, expr2, expr3) ->expr1不為NULL,返回expr2;為NULL,返回expr3。expr2和expr3型別不同的話,expr3會轉換為expr2的型別 NULLIF (expr1, expr2) ->相等返回NULL,不等返回expr1Examine the structure of the PROMOS table:
name Null Type
PROMO_ID NOT NULL NUMBER(3)
PROMO_NAME VARCHAR2(30)
PROMO_START_DATE NOT NULL DATE
PROMO_END_DATE NOT NULL DATE
You want to display the list of promo names with the message 'Same Day' for promos that started and
ended on the same day.
Which query gives the correct output?
A. SELECT promo_name, NVL(NULLIF(promo_start_date, promo_end_date), 'Same Day')
FROM promos;
B. SELECT promo_name, NVL(TRUNC(promo_end_date - promo_start_date), 'Same Day')
FROM promos;
C. SELECT promo_name, NVL2(TO_CHAR(TRUNC(promo_end_date-promo_start_date)), NULL,'Same
Day')
FROM promos;
D. SELECT promo_name, DECODE((NULLIF(promo_start_date, promo_end_date)), NULL,'Same day')
FROM promos;
Answer: D
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14888950/viewspace-1436738/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- nvl, nvl2, nullifNull
- [Developer] NVL,NVL2,NULLIF,COALESCE,DECADE,CASEDeveloperNull
- nvl、nvl2與nullif函式用法區別Null函式
- Oracle-nvl和nvl2函式Oracle函式
- 【函式】oracle nvl2 函式函式Oracle
- 對遠端表使用NVL2的bug
- 新學一個函式nvl2(a,b,c)函式
- Oracle中處理空值的函式nvl-nvl2-lnnvl-nullif的用法Oracle函式Null
- Oracle 中的 TO_DATE 和 TO_CHAR 函式 日期處理Oracle函式
- Oracle中的時間函式用法(to_date、to_char) (總結)Oracle函式
- js日期轉換工具類(仿oracle to_char,to_date等語法)JSOracle
- 【Tip】使用TO_DATE和TO_CHAR函式讓Oracle自己去數數函式Oracle
- nullifNull
- 時間格式化大小寫含義(Java 計算時間差以及比較日期大小 )Java
- pl/sql to_dateSQL
- oracle to_date格式Oracle
- CSS控制大小寫CSS
- mysql大小寫敏感MySql
- Git 區分大小寫Git
- 字串-大小寫轉換字串
- MySQL大小寫問題MySql
- sql server 大小寫敏感SQLServer
- 使用Oracle to_date方法【轉】Oracle
- 字串格式化快速寫法字串格式化
- oracle中ascii函式及to_char函式使用及編碼間的轉換OracleASCII函式
- oracle to_char 函式Oracle函式
- oracle to_char函式Oracle函式
- Oracle to_date()函式的用法Oracle函式
- oracle 報大小寫錯誤Oracle
- JavaScript字母大小寫轉換JavaScript
- JavaScript字串大小寫轉換JavaScript字串
- mysql 大小寫敏感問題MySql
- 密碼區分大小寫密碼
- 英文大小寫轉換
- MySQL中的大小寫敏感MySql
- oracle 不區分大小寫Oracle
- MySQL大小寫敏感說明MySql
- linux檢視目錄大小及硬碟大小Linux硬碟