Some practical suggestions on Oracle SQL Execution Efficiency

Source: Internet
Author: User

The following articles mainly introduce some useful suggestions for improving the execution efficiency of Oracle SQL. The following describes the specific solution and hopes to help you in your future studies. To improve the efficiency of Oracle SQL Execution. We try not to include subqueries in the where clause;

Do not write the Time query as follows:

 
 
  1. where to_char(dif_date,'yyyy-mm-dd')=to_char('2007-07-01','yyyy-mm-dd'); 

In the filter condition, the condition for filtering the maximum number of records must be placed at the end of the where clause;

The FROM clause is written in the base table of the last table, and the driving table is processed first. If the FROM clause contains multiple tables, you must select a table with the least number of records as the base table. If there are more than three join queries, You need to select the cross table intersection table as the basic table. The cross table refers to the table referenced by other tables;

Bind variables

Do not use OR in WHERE

Use EXISTS to replace IN and not exists to replace not in;

Avoid using computation on index columns:

 
 
  1. WHERE SAL*12>25000; 

Replace OR with IN:

 
 
  1. WHERE LOC_ID=10 OR LOC_ID=15 OR LOC_ID=20 

Avoid using is null and is not null in the index column;

Always use the first column of the index;

Replace UNION with UNION-ALL;

Avoid changing the index column type:

 
 
  1. SELECT...FROM EMP WHERE EMPNO='123' 

Due to implicit data type conversion, to_char (EMPNO) = '000000'. Therefore, no index is used. Generally, dynamic Oracle SQL statements are concatenated by strings;

'! = 'No index is used;

Optimize group;

Avoid wildcards with the LIKE parameter. LIKE '4ye % 'uses indexes, but LIKE' % YE 'does not use indexes.

Avoid using difficult regular expressions, such

 
 
  1. select * from customer where zipcode like "98___" 

Even if an index is created on zipcode, sequential scanning is used in this case. If you change the statement

 
 
  1. select * from customer where zipcode>"98000" 

Indexes are used to query queries during query execution, which obviously greatly improves the speed;

Complete Oracle SQL statements as clearly as possible and minimize database work. For example, when writing a SELECT statement, you must explicitly specify the table name of the queried field. Try not to use the SELECT * Statement. Organize SQL statements according to database habits as much as possible.

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.