Usage of exists in Oracle ____oracle

Source: Internet
Author: User
Tags oracle database

Exists can be said to be a more common use of Oracle database development, with exists can improve the efficiency of SQL, can replace in.

exists is to determine whether the SQL statement after exits is true, if the whole SQL sentence is true, otherwise there is no record. Example:

Select 1 from dual where exists (select 1 from dual where 2=1);

There must be no record of the above.

Select 1 from dual where exists (select 1 from dual where 1=1);

The above situation is returned by a record.

Determine if another table contains foreign key records for a table . Example:

SELECT * FROM Table_test a

where exists (select 1 from scott.carol_tmp where pps_master=a.pps_master);

This SQL is to check whether the Pps_master in the Table_test is in carol_tmp. (whether the Carol_tmp table contains foreign key records for the Table_test table)

In fact, the same effect can be achieved, but in the words less efficient, especially in some large tables. The performance of exists and in is reflected.

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.