第二讲函数
适用于年终总结/工作计划/述职报告/策划方案等
2020
Function
Result
大小写处理函数
这些函数转换字符串的大小写
LOWER('SQL Course')
UPPER('SQL Course'nction
Description
MONTHS_BETWEEN ('01-SEP-95','11-JAN-94')
使用日期函数
ADD_MONTHS ('11-JAN-94',6)
NEXT_DAY ('01-SEP-95','FRIDAY')
LAST_DAY('01-FEB-95')
'11-JUL-94'
'08-SEP-95'
'28-FEB-95'
ROUND(SYSDATE,'MONTH') 01-AUG-95
ROUND(SYSDATE ,'YEAR') 01-JAN-96
TRUNC(SYSDATE ,'MONTH') 01-JUL-95
TRUNC(TO_DATE('25-JUL-95') ,'YEAR') 01-JAN-95
使用日期函数
Assume SYSDATE = '25-JUL-95':
TRUNC(SYSDATE ,'YEAR') 01-JAN-95
转换函数
隐式数据类型转换
显式数据类型转换
数据类型转换
显示数据类型转换
NUMBER
CHARACTER
TO_CHAR
TO_NUMBER
DATE
TO_CHAR
TO_DATE
用TO_CHAR处理日期
format_ model:
必须用单引号括起来;
可以包括任何有效的日期形式;
用逗号与日期值分隔。
TO_CHAR(date, 'format_model')
YYYY
日期形式元素
YEAR
MM
MONTH
DY
DAY
Full year in numbers
Year spelled out
Two-digit value for month
Three-letter abbreviation of the day of the week
Full name of the day of the week
Full name of the month
MON
Three-letter abbreviation of the month
DD
Numeric day of the month
用TO_CHAR 函数处理数字
你可以使用一些特殊的形式将数字通过TO_CHAR函数以字符的形式显示出来。
TO_CHAR(number, 'format_model')
9
0
$
L
.
,
代表一个数字
强迫显示0
放置一美元符
使用本地货币符号
显示小数点
显示千位标示符
SELECT TO_CHAR(salary, '$99,') SALARY
FROM employees
WHERE last_name = 'Ernst';
Using the TO_CHAR Function with Numbers
Using the TO_NUMBER and TO_DATE Functions
用TO_NUMBER函数将字符串转换成数字:
使用TO_DATE函数将字符串转换成日期形式:
These functions have an fx modifier. This modifier specifies the exact matching for the character argument and date format model of a TO_DATE function
TO_NUMBER(char[, 'format_model'])
TO_DATE(char[, 'format_model'])
Using the TO_NUMBER and TO_DATE Functions
用TO_NUMBER函数将字符串转换成数字:
使用TO_DATE函数将字符串转换成日期形式:
These functions have an fx modifier. This modifier specifies the exact matching for the character argument and date format model of a TO_DATE function
TO_NUMBER(char[, 'format_model
第二讲函数 来自淘豆网www.taodocs.com转载请标明出处.