1, Function : to_char(hire_date,'format_model')
%@f0]+W9~?0
LS: select last_name, to_char(hire_date,'fmDD Month YYYY')AS HIREDATE
$^)@TL(m0
from employees; ( 17 6月 1987)51Testing软件测试网SqT
U1T t5[(g6KZ
function: to_char(number ,’format_model’)
7go'`e}xWm0
LS: select to_char(salary,'$99,999.00') salary from employees51Testing软件测试网}!D9ao:c6j(Y
where last_name='Ernst'; ($6,000.00)
/?R2}*K;AH)w0
If we change '$99,999.00' into 'L99,999.00', then enquerying result is (RMB6,000.00)51Testing软件测试网(T4^+H(Gu4Z8u
2, function to_number () and to_date()51Testing软件测试网'YJ{K_/?
3,nesting functiom51Testing软件测试网%y1i&jP"[0R
nvl(expr1, expr2) if expr1 is null. Then change expr1 into expr251Testing软件测试网\P#x4{@9E.p |
nvl2(expr1,expr2,expr3) if expr1 isn’t null, change expr2 into expr1, else change expr3 into expr1
-hH,FAz0
4, function nullif()
p#x;etA:l-P0
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)51Testing软件测试网S$m$GVe"~ Mo
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………..
kBr#A+i1h0a*[cx0
6,case expression51Testing软件测试网e5RJ"|m1T
select last_name,job_id,salary,
7q3BUYoxz-c`7o
Y)m0
case job_ID WHEN 'IT_PROG' THEN 1.10*salary51Testing软件测试网*}U] r*UR yp/Yr"Z+J
WHEN 'ST_CLERK' THEN 1.15*salary
4p&[5A|I0
WHEN 'SA_REP' THEN 1.20*salary51Testing软件测试网7clQ^$zbJn&E9_
else salary
r"jSr6E~E6l4W0
end "REVISED_SALARY"
]@^w1d0
FROM employees;
6q#aN4b8X N,U)~0
( 51Testing软件测试网3g!W&H-f*n
King )G-i!ZARH$IK0 |
AD_PRES
p'c&Z}*vyR0 |
24000 +PkWQ,a0 |
24000 Pb-_Kc#R!P&L0 |
Ernst 51Testing软件测试网Pg%|8wp4jva-oA%C |
IT_PROG 51Testing软件测试网k/r5z9KX-fc3k/_!V |
6000 51Testing软件测试网g*sE:l$m Z1C |
6600 UZAu){2O
l0 |
)51Testing软件测试网8W}9xk?A
7,join type: use join to query data from more than one table.
(x5E/M5Z2~zX0
Equijoin : where e.department_id=d.department_id
F[
g
J7GD'p5A;s0
Non-equijoins : where e.salary between j.lowest_sal and j.highest_sal;51Testing软件测试网+b`T3uB3ia
Outer joins ; where e.department_id(+)=d.department_id 51Testing软件测试网9I-\'I^8S7Y%R
Self joins :we should name alias name for the table.51Testing软件测试网e~;D@N7j
Select worker.last_name ||’work for’ || manager.last_name from employees worker ,employees manager where ………..51Testing软件测试网4a)c6?cqQF5T'MJ@
8,Types of group function51Testing软件测试网 V^jH)gs0_ Qk
Avg() :select department_id,avg(salary) from employees group by department_id
-JrgL^L#Q0
select department_id,max(salary) from employees group by department_id;51Testing软件测试网
_:P \EuY
having(max(salary)>10000); (having() can only affect group)
jZq0A:Rc2v0
Count() , count(distinct department_id)/count (department_id)/count(*)
"v
a+^s H ?0
Max()
2baMc"TKM0
Min()
qUXGe?`'P0
Sum()51Testing软件测试网5X!nM#^AX
M'HZ%^.v H l8qr0