您的位置:首页 > 数据库 > Oracle

oracle的分页显示-字符串截取-递归查询

2017-08-08 16:12 190 查看
====================================================

1.oracle 分页查询

参考:http://blog.csdn.net/anxpp/article/details/51534006

====================================================

>>>>>>>>>>>>>>>>>无order by情况下<<<<<<<<<<<<<<<<<<<

====================================================

select * from user where rownum >=3 and rownum <=4;

----------------------------------------------------

oracle机制是第一条行号数据不符合>=3,去掉,原来的第

二行变为第一行,行号还是为1,一直不符合

====================================================

select id,name from(
select rownum rn,u.* from user u)ua

where ua.rn between 3 and 4;

----------------------------------------------------

将行号查询出来生成一个结果集ua,然后在这个结果集中选择

行号大于我们设定的那个值

====================================================

select id,name from(
select rownum rn,u.* from user u where rownum <= 4) ua

where ua.rn >=3 ;

----------------------------------------------------

优化!

====================================================

====================================================

>>>>>>>>>>>>>>>有order by情况下<<<<<<<<<<<<<<<<<<<<<

====================================================

select id,name from (
(select rownum rn,uo.* from
(select * from user u order by name)uo
where rownum <=4)) ua

where ua.rn >=3;

====================================================

====================================================

2.oracle 字符串截取函数

====================================================

SUBSTR  截取子串  INSTR 获取子字符串的位置 注意:!!!substr开始位置从0 instr开始位置从1

通常二者结合使用

例:选取"C3411.907w15"字符串中"."后的字符串

substr("C3411.907w15",instr("C3411.907w15",'.',1,1)+1)

substr("源字符串",开始位置,选取长度)

instr("源字符串","子字符串",开始位置,第几次出现)

=====================================================

For example:

substr("ABCDEFG", 0); //返回:ABCDEFG,截取所有字符 

substr("ABCDEFG", 2); //返回:CDEFG,截取从C开始之后所有字符 

substr("ABCDEFG", 0, 3); //返回:ABC,截取从A开始3个字符 

substr("ABCDEFG", 0, 100); //返回:ABCDEFG,100虽然超出预处理的字符串最长度,但不会影响返回结果,系统按预处理字符串最大数量返回。 

substr("ABCDEFG", -3); //返回:EFG,注意参数-3,为负值时表示从字符串末尾开始查找,字符串排列位置不变。

====================================================

3.oracle 递归查询

参考:http://www.cnblogs.com/wanghonghu/archive/2012/08/31/2665945.html

====================================================

select * from table 

start with 条件一

connect by prior id=parent_id;递归父节点查询/递归子节点查询connect by id = prior parent_id;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: