Execution sequence of oracle clauses

Source: Internet
Author: User

The execution sequence of oracle clauses an SQL statement contains many clauses. When writing SQL statements, it is very important to understand the priority of executing SQL clauses, otherwise, a simple SQL statement may be converted into multiple nested SQL statements, which may lead to incorrect return results. Under www.2cto.com, an example is provided to illustrate the priority of each clause: select a, B, count (sum (c) over () from twhere t. d = 1 start with e is not null connect by prior f = ggroup by a, bhaving sum (c)> 100 order by 3; this SQL contains: 1. SELECT Clause 2. group by clause 3. analysis function 4. from clause 5. where Clause 6. start... connect by clause 7. having clause 8. the order by clause for the FROM clause can be simply understood as a table or a scan (if multi-Table Association is involved, it is complicated and will not be discussed here); www.2cto.com for the SELECT clause, the execution plan is executed at the end. I understand it as returning data to the user rather than reading data. Reading data is performed at the FROM step. The order is 4-> 6-> 5-> 2-> 7-> 3-> 8-> 1 from clause-> start... connect by clause-> where clause-> group by clause-> having clause-> analysis function-> order by clause-> SELECT clause, note that the preceding sequence only indicates general conditions, not all cases follow this execution order, especially when group by and order by are both present. Example: select a, B, count (sum (c) over () from twhere t. d = 1 start with e is not null connect by prior f = ggroup by a, bhaving sum (c)> 100 order by a; the execution sequence of this SQL statement may be: 4-> 6-> 5-> 2 + 8-> 7-> 3-> 1. The actual execution order is based on the execution plan. However, the priority of the following parts is determined regardless of the SQL statement: start... connect by clause-> where clause-> group by clause-> having clause-> Analysis Function

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.