oracle函数

大小写控制函数

upper(upp)---------------UPP

low(LOW)----------------low

initcap(inttcap)---------Initcap

 

字符控制函数

length(csdn)---------------------4

concat(‘con’,‘cat‘)---------concat

substr('csdnblog',1,4)-------------csdn

trim('c'  from 'csdn')----------------sdn

instr('csdnblog','d')-----------------3

lpad(1000,10,'@')----------@@@@@@1000

rpad('csdnblog',10,'@')---------csdnblog@@

数字函数

round(36.989,2)-----------36.99  四舍五入

trunc(36.989,2)------------36.98 截断

mod(36.989,3)----------0.989  取余

 

分组函数

avg

count

sum

max

min

stddev

在分组函数中所有未包含在组函数中的列,都应该包含在group by 中

select  deptno ,avg(sal) ,ename from emp group by deptno,group by ename;

包含在GROUP BY 子句中的列不必包含在SELECT列表中

不能在WHERE子句中使用组函数。

select  * from emp where sal>avg(sal);

可以在HAVING子句中使用组函数。
SELECT   department_id, MAX(salary)
FROM     employees
GROUP BY department_id
HAVING   MAX(salary)>10000 ;
salary大于10000的组将被显示
 
 oracle中的约束
primary key
foreign key
unique
not null
check
 
create table t2(x int primary key );
create table t1
(c1 int not null,
c2 varchar2(10) unique,
c3 int check (c3 >5),
c4 int constraint pk_t primary key,
c5 int,
constraint PK_TF foreign key(c5) references t2(x));
 
删除约束
alter able t1 drop primary key;
alter able t1 drop constraint pk_t;
禁用约束
alter table t1 disable primary key;
alter table t1 disable constraint pk_t ;
激活约束
alter table t1 enable primary key;
 
序列
建序列
create sequence seq
increment by 2
start with 5
minvalue 1
nocycle
cache 5
 
修改序列
ALTER SEQUENCE dept_deptid_seq
               INCREMENT BY 20
               MAXVALUE 999999
               NOCACHE
               NOCYCLE;
 
改变序列的初始值只能通过删除序列之后重建序列的方法实现
 
索引:
一种数据库对象 通过指针
加速 Oracle 服务器的查询速度
通过快速定位数据的方法,减少磁盘 I/O
索引与表相互独立
Oracle 服务器自动使用和维护索引
自动创建: 在定义PRIMARY KEY或UNIQUE约束后系统自动在相应的列上创建唯一性索引
手动创建: 用户可以在其它列上创建非唯一的索引,以加速查询
 
 
 
 
 

你可能感兴趣的:(oracle函数)