1.rownum是伪列,是在获取查询结果集后再加上去的 (获取一条记录加一个rownum)。对符合条件的结果添加一个从1开始的序列号。
eg:
select rownum,phone_no from ur_user_info where rownum < 6;
attention:
rownum是动态的,必有查询结果,然后再给查询的结果集添加上这个列。 例如:第一条记录的rownum是1 ,第二条是2,以此类推。
select rownum, phone_no from ur_user_info where rownum > 5 and rownum < 10; ---查询结果为空集
当产生结果集时,oracle会产生一条rownum为1的记录,显然不符合条件;那么就会产生第二条记录,同样rownum=1,也不符合记录; 一直下去,导致最后上述sql产生的结果集时空集。
如果需要查询到结果,需要使用子查询:
-----错误写法:
select rownum, phone_no
from (select rownum rn , phone_no from ur_user_info ) a
where a.rownum > 5 and a.rownum < 10;
-----正确写法:
select rownum,*
from (select rownum rn, a.* from ur_user_info a where rownum < 10) a
where a.rn > 5;
--注意: 1.rownum只能用< 或者
关注
打赏
热门博文
- ArrayList c.toArray might (incorrectly) not return Object[] (see 6260652)
- Spring框架实体bean转json返回前端报错:Null key for a Map not allowed in JSON (use a converting NullKeySerializer
- python将数据写入txt文本文件
- Python学习随笔:使用xlwings读取和操作Execl文件
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized t
- ‘gbk‘ codec can‘t decode byte 0x80 in position 2: illegal multibyte sequence
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- 关于Mybatis中keyProperty属性
- 解决 Mybatis 报错 org.apache.ibatis.ognl.NoSuchPropertyException: XXXCriteria$Criterion.noValue
- mysql报错 is longer than the server configured value of ‘wait_timeout‘