2016.9.9 "Oracle query optimization rewriting techniques and cases" skills in the Book of Electronics Industry Publishers

Source: Internet
Author: User

1, COALESCE (C1,C2,C3,C4,...) is similar to NVL but can return the first non-null value from multiple expressions

2. To refer to the alias of a column in the Where condition, you can nest a layer of queries again

SELECT * FROM (select salary gz from person) where gz>100

3. The wildcard character of the like () function in addition to the% extra, and _ represents a character, to be escaped in the like expression _ Symbol:

The like (' \_bcd ') escape ' \ ' escape is used to define the escape character, at which point the ' \ \ ' represents the true ' \ ' symbol

4. Numbers such as order by 1 or 2 indicate sort by number of columns (count (1) is it similar? )

5, substr (aa,-3) to take the last 3 digits, but not to specify the starting position, for example, can not use substr (aa,3,-2)

6, sorting when the control of the null record before or after: Order by xx nulls first (nulls last)

7. With. As ... Create a temporary view that exists only when the statement executes

With e as (select ad_hp_id ID, code_id code, txt_name name from ad_hp where code_id like ' zb% ')

Select Id,code, name from E

8. The WHERE and order statements of the LEFT join can be written after the on statement

9, the internal connection is equivalent to the direct where two table fields are equal, only two tables matching data appears

Fully connected two tables all records appear, mismatched items are displayed as null

The left and right connections can be written in the where association, just like the normal two tables, but with the (+) in front of the table condition:

Select a.code_id,b.* from AD_HP A, Bureau b

where a.code_id like ' zb% '

and a.txt_name_admin = B.bureau_code (+)

ORDER by a.code_id

10, 11g after the addition of a number of characters in the statistical string function Regexp_count (' ABABCABCD ', ' a '), the result =3

11, after sorting by a column, take its maximum or minimum value corresponding to the other column max (col1) Keep (Dense_rank first or last order by col2)

If you want to group Intrastat, you can use over (partition by col3). Group by group is also available

Select Max (code_id) Keep (Dense_rank First order by Geo_lat) from AD_HP t where code_id like ' zb% '

12. In the tree data structure, enumerate all the descendants of a node (chapter 12th)

Select Empno as employee code, ename as name, Mgr as Supervisor code, (prior ename) as Supervisor name, Sys_connect_by_path (ename, ', ') as Path

From Scott.emp

Start with empno=7566

Connect by (prior empno) =mgr

2016.9.9 "Oracle query optimization rewriting techniques and cases" skills in the Book of Electronics Industry Publishers

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.