1.在字串型別中的單值函式
lower:全部轉換成小寫
upper:全部轉換成大寫
substr:截取子串
concat:字串拼接
nvl:處理空值
initcap:首字母大寫 其余字母小寫
length:字串長度
注:dual 啞表 滿足select語法結構
select lower('sql oracle') from dual;
select sysdate from dual; //列印當前日期
2.在number型別的單值函式
round:四舍五入
select round(45.523,2) from dual; //45.52
select round(45.523) from dual; //46
select round(45.523,-1) from dual; //50
trunc:只舍不取
select trunc(45.523) from dual; //45
select trunc(45.523,-1) from dual; //40
mod:取余
select mod(1500,400) from dual; //300
3.在日期型別中的單值函式
在更改日期型別時最好將會話(session)設定為英文模式
(alter session set nls_date_language=english; //設定會話語言)
months_between:倆個日期直接相差的月數
add_months:在某個日期加上月數之后的日期
next_day:即將到來的星期幾的日期
last_day:當前日期的月份的最后一天
round:四舍五入 注:對于month 15舍16進 ;對于year 6舍7進
trunc:只舍不取
4.轉換函式:轉換資料型別
to_char
把日期型別轉換成字串型別 sysdate 默認格式DD-MON-YY
select to_char(sysdate,'YYYY-MM-DD hh24-mi-ss PM') time
from dual;
//2020-09-02 15-07-24 PM
把數字型別轉換成字串型別
select to_char(salary,'fm$999,999.00') from s_emp;
select to_char(salary,'L999,999.00') from s_emp;
注:fm去掉前面多余的空格或0
L顯示當地貨幣的符號
,用來分割
.小數點
位數不夠不能正常顯示
0:不足位會自動補位
9:不足為不會自動補位
to_number
把字串型別轉換為日期型別
select to_number('a') from dual;
to_date
把字串轉換成日期型別
//默認日期格式
select to_date('09-JUN-20') "date" from dual;
//不是默認的日期格式 指定日期格式
select to_date('2020-09-20','yyyy-mm-dd') from dual;
例: 查詢全名 全名大寫 first_name長度為6 全名降序
select upper(last_name||','||first_name) name
from s_emp
where length(last_name)=6
order by name DESC;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/1143.html
標籤:Oracle
