Write Oracle hints in the abap SQL statement

Source: Internet
Author: User
① Two methods used:
1. Specify to use full table scan: % _ hints Oracle 'full (table_name )'
2. Specify the index: % _ hints Oracle 'index (table_name index_name )'
For other Oracle hints writing methods, refer to this article: Oracle hint usage
Hint is often used in SQL statement optimization.
② Using secondary Indexes
Consider the following example:
Select * From spfli
% _ Hints Oracle 'index ("spfli" "spfli ~ 001 ")'
.......
Endselect. in the above example, 001 is the secondary index of the table spfli. it's a well-known fact that the efficient way of retrieving data from the database tables is by using secondary indexes. relational database vendors provide the optimizer hints for the same. from sap v4.5, optimizer hints can be provided by the % _ hints parameter. this is dependent on the database systems that support optimizer hints. the point to be noted here is these optimizer hints are not standardized by the SQL standards. each database vendor is free to provide the optimizer hints.
Now to know which index to use for our table:
1. Go to SE11 and there specify the table name
2. now from the menu, Goto --> Indexes
3. Select the required index.
Now suppose that the identifier 001 represents a non-unique secondary index comprising of the columns cityfrom and cityto. The index name shocould be defined:
  
~
Like spfli ~ 001 in the above example. the sequence of fields in the where condition is of no relevance in using this optimizers index. if you specify hints incorrectly, ABAP ignores them but doesn' t return a syntax error or runtime error.
The Code was written in R/3 4.6c.
Code
Consider the following example:
Report suresh_test.
Tables: spfli.
Data: t_spfli like spfli occurs 0 with header line.
Select * From spfli
Into Table t_spfli
% _ Hints Oracle 'index ("spfli" "spfli ~ 001 ")'.
Loop at t_spfli.
Write:/t_spfli.
Endloop.
③ ABAP -- How to specify an index (example) in the SELECT statement)
Report z_generic_test_program.
Tables: csks. start-of-selection.
Select * Up to 10 rows from csks
Where kokrs <> space and
Kostl <> space % _ hints Oracle 'index (csks "J ")'.
Write:/csks. endselect.
④ Control over for all entries hints
Under the heading database interface hints, note 129385 describes the options you have for influencing the database interface by entering hints. the hints are evaluated in the database interface itself and are not passed on to the database. starting with kernel release 4.6b all the above mentioned for all entries parameters can be set via such a hint for a single statement. in the example:
Select * from [...] for all entries in [...] Where [...]
% _ Hints Oracle '& prefer_in_itab_opt 1 & prefer_fix_blocking-1 &'.
This way, the Boolean parameter 'prefer _ in_itab_opt 'is explictly set and the Boolean parameter 'prefer _ fix_blocking' is set to its default value. for all entries hints, like hints are generally only used as a corrective device in
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.