Oracle thinking (4) Oracle's omnipotent paging is not omnipotent 2

Source: Internet
Author: User
I haven't written anything for a long time, because I haven't encountered any problems for a long time. Once and again, I think that Oracle's omnipotent paging is quite refreshing. Today I finally encountered a problem.

Oracle can use SQL statements as parameters to construct a universal paging SQL statement.
"Select * from (select row _. *, rownum _ from (" + SQL ") row _ where
Rownum <= ?) Where rownum _>? "
Oracle uses nested layer-3 query statements and rownum to implement paging, which is the fastest way in Oracle,
If only one or two layers of query statement rownum cannot support order.

For example:
SQL = select * from admin
Concatenate select * from (select row _. *, rownum _ from (select * from admin) row _ where
Rownum <= 110) where rownum _> 100
No problem

But today, a self-recursive parent-child node table is faulty.
The dept table structure is as follows:
Deptid parentid name
1 0 direct Brigade
2 1 directly under the brigade 1 squadron

Entry SQL =
Select
P. tb_parkingbus_id id,
P. tb_eventinfo_id,
P. ajbh,
T. bustypename,
R. resultname,
.....
Dept. dept_name,
Deptoffice. dept_name
From tb_parkingbus p, 'Vehicle table
Tb_1_bustype t, 'Vehicle type table
Tb_cfgbusresult r, 'Vehicle processing result table
Dept, 'level 1 Department table
Dept deptoffice 'level 2 Department table
Where t. bustypecode = p. bustypecode and r. result = p. result and p. sts = 'A' and dept. dept_id = p. dept_id
And dept. parentid = deptoffice. dept_id // Level 2 Department parent node ID = level 1 Department ID
And
P. dept_id = '20140901'
Order by p. ajbh desc

This SQL statement is correct. The SQL statements can be executed normally, but the columns that are not explicitly defined will appear after the SQL statements are substituted into the universal paging SQL statements.

It seems that there is no way

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.