1, Function : to_char(hire_date,'format_model')51Testing软件测试网m4?+v&s|
\:KcF
LS: select last_name, to_char(hire_date,'fmDD Month YYYY')AS HIREDATE
:_w@ N.uq9Pj3H0
from employees; ( 17 6月 1987)51Testing软件测试网0_#rf|]2Zvb7Wq
function: to_char(number ,’format_model’)51Testing软件测试网_p8Y%_I!eOw;[
LS: select to_char(salary,'$99,999.00') salary from employees
A^ g(};j9^ Xk0
where last_name='Ernst'; ($6,000.00)
Zm'U7e%z.`/v0
If we change '$99,999.00' into 'L99,999.00', then enquerying result is (RMB6,000.00)
!m:Ot2@U0
2, function to_number () and to_date()51Testing软件测试网0M(E3c Ec'B
3,nesting functiom
7wYSN.[T0dR0
nvl(expr1, expr2) if expr1 is null. Then change expr1 into expr251Testing软件测试网/]2wY7\)Z@
nvl2(expr1,expr2,expr3) if expr1 isn’t null, change expr2 into expr1, else change expr3 into expr151Testing软件测试网
rv${N9Rx h(u._
4, function nullif()
8G
A]"x!g5Tx
p6kK0
nullif(length(last_name),length(first_name)) , if length(last_name)=length(first_name), then values of nullif() is null, else …..is length(last_name)
$Ar
Bl'[Q`6c4Y
o4J0
5,function coalesce(1,2,3, ) if 1 isn’t null, the values of this function is 1, else judge 2,if 2 isn’t null, then 2 is this function’s values,else………..
wrL
Q7H9OT2?T%i5o$m0
6,case expression
a%T:vD/K\ Kc0
select last_name,job_id,salary,51Testing软件测试网|+L
F$X;K
KQ
case job_ID WHEN 'IT_PROG' THEN 1.10*salary51Testing软件测试网l d'v?Irw'O
WHEN 'ST_CLERK' THEN 1.15*salary
J:tW E%|Tlb0
WHEN 'SA_REP' THEN 1.20*salary
_{J
C(@%J0
else salary
0T)s!?
i:T0
end "REVISED_SALARY"
O(`:K8p$i:QF!~
I0
FROM employees;
)@2m7cM6Ms0
(
9_CR6l%L R
s
ce0
King 51Testing软件测试网M
X TZ0Ck |
AD_PRES 51Testing软件测试网d$HZ%ZT f |
24000 W
CRur#z`aS lZ.Fp0 |
24000 51Testing软件测试网
\(X}6dH~En |
Ernst R:F4l,R:a"Mi0 |
IT_PROG 51Testing软件测试网l~$JwY3krj |
6000 51Testing软件测试网4P!Sg%Nc#V;N$Mkp#^ |
6600 51Testing软件测试网0e"R6DrZ1vC |
)
?Sq7zt5U"s0
7,join type: use join to query data from more than one table.51Testing软件测试网!z@)@ U5^Z.a/]GR
Equijoin : where e.department_id=d.department_id
;W0L@
R[0
Non-equijoins : where e.salary between j.lowest_sal and j.highest_sal;51Testing软件测试网;W6vno F x%t.~
Outer joins ; where e.department_id(+)=d.department_id
?.A"o3{&oJDETo0
Self joins :we should name alias name for the table.
l+[ ]'q4n4`1L0
Select worker.last_name ||’work for’ || manager.last_name from employees worker ,employees manager where ………..
\"e'r
K+q0
8,Types of group function51Testing软件测试网-C[Y;bk
_!qgiT
Avg() :select department_id,avg(salary) from employees group by department_id51Testing软件测试网VE7EFv9r"r/Y
select department_id,max(salary) from employees group by department_id;
,|Y9O5~*uB&GdJd0
having(max(salary)>10000); (having() can only affect group)51Testing软件测试网-MBQ)Fmvi3d?
Count() , count(distinct department_id)/count (department_id)/count(*)
{fX,RRh5z
lpR0
Max()
uNT?9[;Ky0?M0|5y U1B0
Min()
iCa(S'};Cw^0
Sum()51Testing软件测试网R1]Gho2o)@|0rH Y(I
.F+H4dvy Nw0