--书分类目录kind
--涂聚文 Geovin Du
create table geovindu.BookKindList
(
BookKindID INT PRIMARY KEY,
BookKindName nvarchar2(500) not null,
BookKindParent INT null,
BookKindCode varchar(100) ---編號
);
--序列创建 drop SEQUENCE BookKindList_SEQ; CREATE SEQUENCE geovindu.BookKindList_SEQ
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
NOCACHE; --设置缓存cache个序列,如果系统down掉了或者其它情况将会导致序列不连续,也可以设置为---------NOCACHE --自增长触发器
drop trigger BookKindList_ID_AUTO; create or replace trigger geovindu.BookKindList_ID_AUTO
before insert on geovindu.BookKindList --BookKindList 是表名
for each row
declare
nextid number;
begin
IF :new.BookKindID IS NULL or :new.BookKindID=0 THEN --BookKindID是列名
select geovindu.BookKindList_SEQ.Nextval --BookKindList_SEQ正是刚才创建的
into nextid
from dual;
:new.BookKindID:=nextid;
end if;
end; --对表的说明
comment on table geovindu.BookKindList is '书分类目录';
--对表中列的说明
comment on column geovindu.BookKindList.BookKindID is '目录ID';
comment on column geovindu.BookKindList.BookKindName is '目录名称';
comment on column geovindu.BookKindList.BookKindParent is '目录父ID';
comment on column geovindu.BookKindList.BookKindCode is '目录code'; declare
gg nvarchar2(500):='geovindu2';
dd nvarchar2(500):='d';
begin
select REPLACE(gg, chr(10), '') into dd from dual;
dbms_output.put_line(dd);
end; insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('六福书目录',0,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('自然科学',1,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('社会科学',1,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('文学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('设计艺术',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('小说',4,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('诗词散曲',4,'');
COMMIT;
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('文学理论',4,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('小品',4,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('杂文',4,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('散文',4,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('文言文',4,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('设计理论',5,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('平面设计',5,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('立体设计',5,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('影像设计',5,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('广告设计',5,'');
COMMIT;
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('数学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('物理',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('化学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('生物学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('医学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('天文学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('地理学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('空间理论学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('环境环保学',2,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('工程学',2,'');
COMMIT;
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('心理学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('经济学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('统计学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('审计学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('会计学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('社会学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('哲学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('宗教学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('政治学',3,'');
insert into geovindu.BookKindList(BookKindName,BookKindParent,BookKindCode) values('法学',3,'');
COMMIT; -- 通过分析函数分页
declare pageNumber int:=1;
pageSize int:=10;
begin
pageNumber:=1;
pageSize:=5;
--1
SELECT t2.BookKindName,t2.BookKindParent,t2.BookKindID FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID,ROW_NUMBER() OVER(ORDER BY t1.BookKindID) rn
FROM geovindu.BookKindList t1
) t2 WHERE t2.rn >= ((pageNumber-1)*pageSize+1) AND t2.rn <= (pageNumber*pageSize);
end; declare pageNumber int:=1;
pageSize int:=10;
rid int:=0;
begin
pageNumber:=1;
pageSize:=5;
SELECT t2.BookKindName,t2.BookKindParent,t2.BookKindID
FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID,ROW_NUMBER() OVER(ORDER BY t1.BookKindID) rn
FROM geovindu.BookKindList t1
) t2 WHERE t2.rn >= ((pageNumber-1)*pageSize+1) AND t2.rn <= (pageNumber*pageSize);
end; --
select * from (select rownum rn,a.* from (select BookKindName,BookKindParent,BookKindID from geovindu.BookKindList) a where rownum<=10) where rn>=6; SELECT t2.BookKindName,t2.BookKindParent,t2.BookKindID FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID,ROW_NUMBER() OVER(ORDER BY t1.BookKindID) rn
FROM geovindu.BookKindList t1
) t2 WHERE t2.rn >= ((1-1)*5+1) AND t2.rn <= (1*5); --2
SELECT t2.BookKindName,t2.BookKindParent,t2.BookKindID FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID,ROW_NUMBER() OVER(ORDER BY t1.BookKindID) rn
FROM geovindu.BookKindList t1
) t2 WHERE t2.rn >= ((2-1)*5+1) AND t2.rn <= (2*5); --3
SELECT t2.BookKindName,t2.BookKindParent,t2.BookKindID FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID,ROW_NUMBER() OVER(ORDER BY t1.BookKindID) rn
FROM geovindu.BookKindList t1
) t2 WHERE t2.rn >= ((3-1)*5+1) AND t2.rn <= (3*5); SELECT t1.BookKindName,t1.BookKindParent,ROW_NUMBER() OVER(ORDER BY t1.BookKindID) rn
FROM geovindu.BookKindList t1 -- 1.2、通过 ROWNUM 分页
SELECT t3.BookKindName,t3.BookKindParent,t3.BookKindID FROM(
SELECT t2.*,ROWNUM rn FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID FROM geovindu.BookKindList t1 ORDER BY t1.BookKindID
) t2 WHERE ROWNUM <= (1*5)
) t3 WHERE t3.rn >= ((1-1)*5+1); SELECT t3.BookKindName,t3.BookKindParent,t3.BookKindID FROM(
SELECT t2.*,ROWNUM rn FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID FROM geovindu.BookKindList t1 ORDER BY t1.BookKindID
) t2 WHERE ROWNUM <= (2*5)
) t3 WHERE t3.rn >= ((2-1)*5+1); --通过 ROWNUM 分页的一种变通写法(相对来说更好理解):
SELECT t3.BookKindName,t3.BookKindParent,t3.BookKindID FROM(
SELECT t2.*,ROWNUM rn FROM(
SELECT t1.BookKindName,t1.BookKindParent,t1.BookKindID FROM geovindu.BookKindList t1 ORDER BY t1.BookKindID
) t2
) t3 WHERE t3.rn >= ((1-1)*5+1) AND t3.rn <= (1*5); -- 1.3、通过 ROWID 分页
SELECT t4.BookKindName,t4.BookKindParent,t4.BookKindID
FROM geovindu.BookKindList t4
WHERE t4.ROWID IN(
SELECT t3.BookKindID FROM(
SELECT t2.BookKindID,ROWNUM rn FROM(
SELECT t1.ROWID BookKindID FROM geovindu.BookKindList t1 ORDER BY t1.BookKindID
) t2 WHERE ROWNUM <= (1*5)
) t3 WHERE t3.rn >= ((1-1)*5+1)
) ORDER BY t4.BookKindID; SELECT t4.BookKindName,t4.BookKindParent,t4.BookKindID
FROM geovindu.BookKindList t4
WHERE t4.ROWID IN(
SELECT t3.BookKindID FROM(
SELECT t2.BookKindID,ROWNUM rn FROM(
SELECT t1.ROWID BookKindID FROM geovindu.BookKindList t1 ORDER BY t1.BookKindID
) t2 WHERE ROWNUM <= (2*5)
) t3 WHERE t3.rn >= ((2-1)*5+1)
) ORDER BY t4.BookKindID; SELECT t4.BookKindName,t4.BookKindParent,t4.BookKindID
FROM geovindu.BookKindList t4
WHERE t4.ROWID IN(
SELECT t3.BookKindID FROM(
SELECT t2.BookKindID,ROWNUM rn FROM(
SELECT t1.ROWID BookKindID FROM geovindu.BookKindList t1 ORDER BY t1.BookKindID
) t2 WHERE ROWNUM <= (3*5)
) t3 WHERE t3.rn >= ((3-1)*5+1)
) ORDER BY t4.BookKindID;

  用的Toad for Oracle 12.1 编辑,Oracle 10g

Sql: Oracle paging的更多相关文章

  1. 常用SQL[ORACLE]

        1.常用系统函数 2.常用sql语句 3.一些定义和关键字 4.需要注意点   1.常用系统函数 ↑ --decode decode(column,if_value,value,elseif_ ...

  2. [PL/SQL]oracle数据库的导出导入

    一.PL/SQL Developer工具一般对oracle的导入导出有以下4中方式: 1.Oracle导出导入方式 这种方式导出导入为.dmp的文件格式,.dmp文件是二进制的,可以跨平台,还能包含权 ...

  3. [SQL]oracle 的to_char、to_number、to_date用法

    关键字: oracle 的to_char.to_number.to_date用法 TO_CHAR 是把日期或数字转换为字符串TO_DATE 是把字符串转换为数据库中得日期类型转换函数TO_NUMBER ...

  4. SQL(Oracle)日常使用与不常使用函数的汇总

    --日常使用的sql语句和oracle语句,有些相对使用的频率比较高,收藏起来还是比较值得的 -- 绝对值 SQL:) value Oracle:) value from dual -- 2.取整(大 ...

  5. pl/sql oracle

    http://uule.iteye.com/blog/2061773(出处) 批量导入脚本: 打开一个command window  > 输入@ > 它会让你选择要导入的文件 (自己要知道 ...

  6. PL/SQL + Oracle客户端 配置记录

    oracle一直都没怎么用. oracle pl/sql也是在别人帮助下完成配置. 这次电脑重装后,自己搞定总结了下怎么配置. 1.下载Oracle 客户端. 安装的版本是win64_11gR2_cl ...

  7. pl/sql oracle数据库中文数据显示异常或者不能使用中文查询的解决办法

    1首先我们需要找到pl/sql developer 目录 然后在该目录下 创建一个bat文件 在文件中定义 set NLS_LANG=AMERICAN_AMERICA.UTF8start PLSQLD ...

  8. sql: Oracle simple example table

    --Oracle 9i 实例数据脚本地址:$oracle_home/rdbms/admin/utlsampl.sql CREATE TABLE DEPT (DEPTNO NUMBER(2) CONST ...

  9. sql: Oracle 11g create table, function,trigger, sequence

    --书藉位置Place目录 drop table BookPlaceList; create table BookPlaceList ( BookPlaceID INT PRIMARY KEY, -- ...

随机推荐

  1. SpringMVC 请求参数绑定

    什么是请求参数绑定 请求参数格式 默认是key/value格式,比如:http:xxxx?id=1&type=2 请求参数值的数据类型 都是字符串类型的各种值 请求参数值要绑定的目标类型 Co ...

  2. ElasticSearch如何一次查询出全部数据—基于Scroll

    Elasticsearch 查询结果默认只显示10条,可以通过设置from及size来达到分页的效果(详见附3),但是 from + size <= 10,000,因为index.max_res ...

  3. k8s 上使用 StatefulSet 部署 zookeeper 集群

    目录 StatefulSet 部署 zookeeper 集群 创建pv StatefulSet 测试 StatefulSet 部署 zookeeper 集群 参考 k8s官网zookeeper集群的部 ...

  4. for循环、while循环、break跳出循环、continue结束本次循环、exit退出整个脚本

    7月13日任务 20.10 for循环20.11/20.12 while循环20.13 break跳出循环20.14 continue结束本次循环20.15 exit退出整个脚本扩展select用法 ...

  5. centos7 安装wps

    # cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) # cat /proc/version Linux version 3.1 ...

  6. AQS系列(一)- ReentrantLock的加锁

    前言 AQS即AbstractQueuedSynchronizer,是JUC包中的一个核心抽象类,JUC包中的绝大多数功能都是直接或间接通过它来实现的.本文是AQS系列的第一篇,后面会持续更新多篇,争 ...

  7. 《Windows内核安全与驱动开发》4.1 文件操作

    <Windows内核安全与驱动开发>阅读笔记 -- 索引目录 <Windows内核安全与驱动开发>4.1 文件操作 从 C:\a.txt 中读取一部分内容并利用 DbgPrin ...

  8. js4——字符转化

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. 深度研究:回归模型评价指标R2_score

    回归模型的性能的评价指标主要有:RMSE(平方根误差).MAE(平均绝对误差).MSE(平均平方误差).R2_score.但是当量纲不同时,RMSE.MAE.MSE难以衡量模型效果好坏.这就需要用到R ...

  10. componentWillMount VS componentDidMount

    前言 这与React组件的生命周期有关,组件挂载时有关的生命周期有以下几个: constructor(){} componentWillMount(){} render(){} componentDi ...