一
算術運算符
連接運算符
比較運算符
邏輯運算符
集合運算符
要求
查詢中不能包含long 列
列的標簽是第一個集合的標簽
使用order by時
例
intersect
select * from emp intersect select * from emp where deptno=
select * from emp minus select * from emp where deptno=
select * from emp where deptno=
select * from emp where deptno=
二
TO_DATE格式(以時間:
Year:
yy two digits 兩位年 顯示值:
yyy three digits 三位年 顯示值:
yyyy four digits 四位年 顯示值:
Month:
mm number 兩位月 顯示值:
mon abbreviated 字符集表示 顯示值:
month spelled out 字符集表示 顯示值:
Day:
dd number 當月第幾天 顯示值:
ddd number 當年第幾天 顯示值:
dy abbreviated 當周第幾天簡寫 顯示值:星期五
day spelled out 當周第幾天全寫 顯示值:星期五
ddspth spelled out
Hour:
hh two digits
hh
Minute:
mi two digits
Second:
ss two digits
其它
Q digit 季度 顯示值:
WW digit 當年第幾周 顯示值:
W digit 當月第幾周 顯示值:
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_date(
顯示Two Hundred Twenty
select to_char(to_date(
星期一
select to_char(to_date(
monday
設置日期語言
ALTER SESSION SET NLS_DATE_LANGUAGE=
也可以這樣
TO_DATE (
select floor(sysdate
select id
UNION
select
注意要用TO_DATE(null)
a_date between to_date(
那麼
所以
輸入的格式要看你安裝的ORACLE字符集的類型
alter system set NLS_DATE_LANGUAGE = American
alter session set NLS_DATE_LANGUAGE = American
或者在to_date中寫
select to_char(to_date(
注意我這只是舉了NLS_DATE_LANGUAGE
可查看
select * from nls_session_parameters
select * from V$NLS_PARAMETERS
select count(*)
from ( select rownum
from all_objects
where rownum <= to_date(
)
where to_char( to_date(
not in (
查找
在前後分別調用DBMS_UTILITY
select months_between(to_date(
select months_between(to_date(
Next_day(date
Monday
Mon
select to_char(sysdate
注意
可以建立一個函數來處理這個問題
create or replace function sys_date return date is
begin
return sysdate;
end;
select to_char(sys_date
extract()找出日期或間隔值的字段值
SELECT EXTRACT(HOUR FROM TIMESTAMP
SQL> select sysdate
SYSDATE TO_CHAR(SYSDATE
SQL> select sysdate
SYSDATE TO_CHAR(SYSDATE
select older_date
newer_date
years
months
abs(
trunc(
newer_date
add_months( older_date
)
) days
from ( select
trunc(months_between( newer_date
mod(trunc(months_between( newer_date
newer_date
older_date
from (
select hiredate older_date
from emp
)
)
select to_char(add_months(last_day(sysdate) +
select add_months(trunc(sysdate
閏年的處理方法
to_char( last_day( to_date(
如果是
yyyy
rrrr
yyyy
rrrr
select to_char( NEW_TIME( sysdate
from dual;
Select TO_DATE(FLOOR(TO_CHAR(sysdate
from dual
SSSSS表示
select TO_CHAR(SYSDATE
select
Days
A
TRUNC(A*
TRUNC(A*
TRUNC(A*
TRUNC(A*
from
(
select
trunc(sysdate) Days
sysdate
from dual
)
select * from tabname
order by decode(mode
//
floor((date
floor((date
d(mod(date
next_day(sysdate
日 一 二 三 四 五 六
select (sysdate
日期 返回的是天 然後 轉換為ss
select sysdate S
round(sysdate) S
round(sysdate
round(sysdate
round(sysdate
select sysdate S
trunc(sysdate) S
trunc(sysdate
trunc(sysdate
trunc(sysdate
from dual
select greatest(
注:oracle時間差是以天數為單位
select floor(to_number(sysdate
select ceil(moths_between(sysdate
select floor(to_number(sysdate
select floor(to_number(sysdate
select floor(to_number(sysdate
select floor(to_number(sysdate
注:oracle時間加減是以天數為單位
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
select to_char(sysdate
SELECT Trunc(Trunc(SYSDATE
Trunc(SYSDATE
Trunc(SYSDATE
LAST_DAY(Trunc(SYSDATE
FROM dual;
三
select substr(
select instr(
select
select ltrim(
rtrim(
trim(
select trim(leading
trim(trailing
trim(
select ascii(
select chr(
select length(
select lower(
upper(
initcap(
from dual;
select replace(
select translate(
select lpad(
select lpad(dname
select deptno
例:
select seed
select seed
SELECT CASE X
WHEN X
WHEN X
WHEN X
ELSE
END
FROM DUAL
注:CASE語句在處理類似問題就顯得非常靈活
四
select ceil(
select power(
select mod(
select round(
select sign(
五
to_char(sysdate
to_char(sysdate
to_char(sysdate
to_char(sysdate
to_char(sysdate
from dual;
insert into emp(empno
select to_number(to_char(sysdate
六
返回登錄的用戶名稱
select user from dual;
返回表達式所需的字節數
select vsize(
ex
例
select comm
值相等返空
例
select nullif(sal
返回列表中第一個非空表達式
select comm
如果ex
如
select nvl
七
max min avg count sum
select max(ename)
min(ename)
avg(sal)
count(*)
sum(sal) from emp where deptno=
select deptno
min(ename)
avg(sal)
count(*)
sum(sal) from emp group by deptno;
select deptno
min(ename)
avg(sal)
count(*)
sum(sal) from emp group by deptno having deptno=
select deptno
variance 返回一組值的方差差
select deptno
rollup 按分組的第一個列進行統計和最後的小計
cube 按分組的所有列的進行統計和最後的小計
select deptno
select deptno
cube 產生組內所有列的統計和最後的小計
select deptno
八
只在會話期間或在事務處理期間存在的表
臨時表在插入數據時
create global temporary table temp_dept
(dno number
dname varchar
on commit delete rows;
insert into temp_dept values(
commit;
select * from temp_dept;
on commit preserve rows:在會話期間表一直可以存在(保留數據)
on commit delete rows:事務結束清除數據(在事務結束時自動刪除表的數據)
除法
select MOD(
select trunc(
select ceil(
From:http://tw.wingwit.com/Article/program/Oracle/201311/19033.html