Oracle's scattered notes

Source: Internet
Author: User

Some scattered notes in Oracle prevent repeated insertion of an SQL insert record. However, in some special applications, before inserting a record, you must check whether the record already exists, the insert operation is performed only when the record does not exist. How can we ensure that duplicate records are not inserted? Use the EXISTS condition to prevent repeated records from being inserted. 1. Before inserting a single record, you must check whether the record exists. The insert operation is performed only when the record does not exist. Insert into clients (client_id, client_name, client_type) SELECT 10345, 'ibm ', 'advertising' FROM dual WHERE not exists (select * from clients where clients. client_id = 10345); 2. before inserting multiple records, you must check whether this record exists. The insert operation is performed only when the record does not exist. Insert into clients (client_id, client_name, client_type) SELECT supplier_id, supplier_name, 'advertising 'FROM suppliers WHERE not exists (select * from clients where clients. client_id = suppliers. supplier_id); Syntax: EXISTS subquery parameter: subquery is a restricted SELECT statement (COMPUTE clauses and INTO keywords are not allowed ). Result type: Boolean. If the subquery contains rows, TRUE is returned. Otherwise, FLASE is returned. Conclusion: The Return Value of the EXISTS (including not exists) clause is a BOOL value. EXISTS has a subquery Statement (SELECT... FROM...), which can be called an EXIST internal query statement. The query statement returns a result set. The EXISTS clause returns a Boolean value (True or False) based on whether the result set of the query statement is null or not (this subquery does not actually return any data ).

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.