oracle 大小写敏感 有一个伪表-->dual
nvl("","") 去除字段中的null值,并用第二个参数替代。在oracle中,一个数和null运算会得null,所以需要这个函数.
例子: select
ename,sal*12+nvl(comm,0)
from
emp;
Concat("","") 这是拼接的方式,将参数一和参数2拼接到一起
例子: select
Concat(Concat('编号:',empno),Concat('姓名:',ename))
from
emp;
|| 双竖线的方式也可以用来拼接
例子: select
'编号:'||empno||'姓名:'||ename
from
emp;
to_date('','') 字符串类型转换为日期类型,参数一为字符串,参数二是日期格式
例子: select
*
from
emp
where
hiredate between
to_date('1981-1-1','yyyy-mm-dd')
and
to_date('1981-12-31','yyyy-mm-dd');
nulls first/nulls last null值在前面或者在后面
例子: select
ename,comm
from
emp
order
by
comm
desc
nulls
last;
例子: select
ename,comm
from
emp
order
by
comm
desc
nulls
first;
upper() 将字符串转为大写
例子: select
upper('smith')
from
dual;
lower() 将返回值转换为小写
例子: select
lower(ename)
from
emp;
initcap() 将首字母转大写
例子: select
initcap('smith')
from
dual;
substr('',,) 截取字符串的方法:参数一:需要截取的字符串,参数二:开始索引,参数三:截取的长度。
例子: select
substr('helloworld',0,5)
from
dual;
length() 获取返回值的长度
例子: select
length(ename)
from
emp
where
ename =
'SMITH';
replace('','','') 替换字符串:
例子: select
replace('hello','l','x')
from
dual;
round() 四舍五入运算
例子: select
round(15.66)
from
dual;--16
selectround(15.66,-2)
from
dual;--0
selectround(15.66,-1)
from
dual;--20
select
round(15.66,0)
from
dual;--16
select
round(15.66,1)
from
dual;--16.7
select
round(15.66,2)
from
dual;--15.66
trunc() 进行截断操作
例子: select
trunc(15.66)
from
dual;--15
select
trunc(15.66,-2)
from
dual;--0
select
trunc(15.66,-1)
from
dual;--10
select
trunc(15.66,0)
from
dual;--15
select
trunc(15.66,1)
from
dual;--15.6
select
trunc(15.66,2)
from
dual;--15.66
mod(,) 求余数操作
例子: select
mod(15,3)
from
dual;
sysdate 查询系统时间
例子: select
sysdate
from
dual;
months_between('','') 查询月数:参数一:近期月数,参数2:远期月数
例子: select
months_between(sysdate,hiredate)
from
emp;
add_months(,) 月数+n:参数一:日期1,参数二:加上的月数
例子: select
add_months(hiredate,3)
from
emp;
to_char('','') 将日期转换为指定格式的日期形式
例子: select
to_char(sysdate,'yyyy-mm-dd')
from
dual;
将日期转化为年月日格式:
例子: select
to_char(sysdate,'yyyy')||'年'||to_char(sysdate,'mm')||'月'||to_char(sysdate,'dd')||'日'
from
dual;
nvl2('',,) 判断是否为空 参数一:被判断的,参数二:不为空返回,参数三:为空返回
例子: select
nvl2(1,1,2)
from
dual;
decode(,'','',......) 对列中的数据转换中文显示:参数一:要转换的列名,参数二:要转换的字符,参数三:转换的结果,参数四一直到后面同参数二参数三,后面如果不写,则全部转换为null
例子: select
ename,decode(job,'CLERK','工作1','SALESMAN','工作2')
from
emp;
例子: select
ename,decode(job,'CLERK','工作1','SALESMAN','工作2','其它')
from
emp;
case when then end 效果同上
例子: select
case
job
when
'CLERK'
then
'工作1'
when
'SALESMAN'
then
'工作2'
else
'其它'
end
from
emp;
oracle 分页查询公式:
select
*
from
(select
rownum
r,e.*
from
(select
*
from
表名
order
by
sal
desc) e) e1
where
e1.r > (pageNo -
1)*pageSize
and
e1.r<=pageNo*pageSize
PL/SQL:
declare 定义一个变量
:= 为变量赋值
begin
你的处理语句
end;
变量的定义规则:
if语法:
if---end if
if---elsif
if---else---end if
循环:
while 条件 loop 循环体 end loop;
loop (循环体) exit when 退出条件 (循环体) end loop;
for i in 1..100 loop 循环体 end loop;
游标:cursor
游标的使用:
存储过程:
存储函数:
存储过程和存储函数的区别:
存储函数和存储过程在java中的调用:
java:
游标引用:(其中第二个参数是输出的游标,在存储过程中只是打开了游标而没有关闭游标,关闭的游标需要在java代码中实行)
java:
触发器:
触发器定义语法
例子:
create or replace trigger myTrigger
after
insert on Person
declare
begin
dbms_output_put_line('一个员工被插入了');
end myTrigger;