Insert data after simple Oracle judgment

Source: Internet
Author: User


Sometimes using Oracle's database, you need to judge when inserting data. For example, each person can only write one article per day.
In the insertion of the time to make a judgment, check whether there is a person on the day of the operation of the record.
Will first

1.select Count (*) from XXX

A moment.
This day checked, there is a way to do without first select
was supposed to be

The code is as follows Copy Code

1.insert
2.into form (Formid) VALUES (111)

Change into

The code is as follows Copy Code

1.insert
2.when (Not EXISTS (select 1 from form where formid =)) Then
3.into form (formid) select from dual

In this way, when there is a formid=111 record in the database, the insert operation is not performed.

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.