Oracle表空间 与 分页
Oracle表空间
一个表空间可以包含1至n个数据文件
一个数据文件必然属于某个表空间
表空间的构建以及数据文件的挂接
create tablespace mytbs datafile '/u01/app/oracle/oradata/orcl/data_1.dbf' size 100m;
create tablespace mytbs2 datafile '/u01/app/oracle/oradata/orcl/data_2.dbf' size 100m, '/u01/app/oracle/oradata/orcl/data_3.dbf' size 100m;
//创建临时表空间
create temporary tablespace mytemp
tempfile '/u01/app/oracle/oradata/orcl/my_temp.dbf' size 100m
创建一个用户,并指定专有的永久表空间和临时表空间
create user tester2 identified by abc123
default tablespace mytbs2
temporary tablespace mytemp;
伪列
rowid
64进制 a-z 26 A-Z 26 0-9 10 62
rowid可以分析出这条记录在磁盘上的具体位置
rowid和rownum是不存在的字段,是实时计算的,所以我们也把这两个字段叫做伪列。
rownum会自动给你所得到的记录进行数字编号,从1开始。我们经常用rownum来分页。
分页
select rownum,a.* from tbl_student a where rownum>=4
大于运算:仅当所有的数据均大于等于4时,数据方能取出
小于运算正常
rownum仅仅支持小于运算,不支持大于运算
create table tbl_student(
stu_no char(4) primary key,
stu_name varchar2(30) not null,
stu_mark int not null
);
insert into tbl_student values('0010','mary',89);
insert into tbl_student values('0016','david',67);
insert into tbl_student values('0009','jenny',90);
insert into tbl_student values('0001','mike',76);
insert into tbl_student values('0190','王有财',83);
insert into tbl_student values('0234','刘涛',34);
insert into tbl_student values('0011','王七',56);
insert into tbl_student values('0018','刘武',59);
insert into tbl_student values('0191','王有财1',63);
insert into tbl_student values('0235','刘涛1',39);
insert into tbl_student values('0015','王七1',58);
insert into tbl_student values('0118','刘武1',79);
select rownum,a.* from tbl_student a;
//取不出任何数据
select rownum,a.* from tbl_student a where rownum>=4 and rownum<=6;
//效率低下
select *
from
(
select rownum rn,a.* from tbl_student a
)
where rn>=4 and rn<=6
//可以取出数据
select *
from
(
select rownum rn,a.* from tbl_student a where rownum<=6
)
where rn>=4
select *
from
(
select rownum rn, a.*
from
(
select * from tbl_student order by stu_mark
) a
where rownum<=6
)
where rn>=4
//ORACLE分页公式
select * from
(
select rownum rn, a.* from
(SQL CLAUSE) a
where rownum<=:endScope
)
where rn>=:beginScope