--书分类目录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. Ubuntu 一键伪装成Win 10,Kali Linux 2019 kali-undercover软件嫁接;

    今天,下午刷手机的时候,突然看到kali出了一个非常新颖的主题:该主题可以使得kali系统伪装成windows 10而变得低调起来:就像下面这样: 具体新闻链接:https://www.freebuf ...

  2. Vue项目解析

    各个文件夹 node_modules:用来放环境依赖 public:用来放公共资源,里面的index.html文件,就是初始的挂载点.被app.vue给取代了. src:放各种资源的. assets: ...

  3. Android 子线程更新UI 异常

    众所周知,Android是不可以在子线程中直接更新UI的,需要借助Handler或者View.post(Runnable runnable)或者runOnUIThread(Runnable runna ...

  4. 2019-2020-11 20199317 《Linux内核原理与分析》 第十一周作业

    ShellShock 攻击实验 1  ShellShock 简介      Shellshock,又称Bashdoor,是在Unix中广泛使用的Bash shell中的一个安全漏洞,首次于2014年9 ...

  5. DateTime格式转换部分介绍

    DateTime与字符串转换: DateTime()与转换为字符串主要依靠DateTime().ToString(string format) 函数,以我的理解,参数format大体分为单个字母和多个 ...

  6. java基础-泛型举例详解

    泛型 泛型是JDK5.0增加的新特性,泛型的本质是参数化类型,即所操作的数据类型被指定为一个参数.这种类型参数可以在类.接口.和方法的创建中,分别被称为泛型类.泛型接口.泛型方法. 一.认识泛型 在没 ...

  7. luogu P1908 逆序对 |树状数组

    题目描述 猫猫TOM和小老鼠JERRY最近又较量上了,但是毕竟都是成年人,他们已经不喜欢再玩那种你追我赶的游戏,现在他们喜欢玩统计.最近,TOM老猫查阅到一个人类称之为"逆序对"的 ...

  8. jQuery中的基本选择器,id,class,元素,通用

    常用的基本选择器: 后续的补充选择器 为了后面看的方便,我们先将body中的内容展示出来: <body> <p> 账号:<input type="text&qu ...

  9. Python元组tuple(不可变)

    Python元组Tuple(不可变): 元组的特点: 1.元组的初始化: tuple = (1, )  #元组只有一个元素的话,初始化时要加,否则当做元素的普通变量类型处理 tuple = (1, 2 ...

  10. [TimLinux] docker CentOS7 入门——容器(1)

    1. 编写Dockerfile # 将官方 Python 运行时用作父镜像 FROM python: # 将工作目录设置为 /app WORKDIR /app # 将当前目录内容复制到位于 /app ...