How to insert data to a view in Oracle

Source: Internet
Author: User

Insert view conditions:
1. if a view is generated based on a basic table, this is called a non-join view. All non-join views can be updated, that is, they can be performed on the view, insert, update, delete operation.
2. for a connection view, follow the basic update rules. now I only want to explain the insert criterion: the insert statement cannot explicitly or implicitly reference any non-code reserved fields in the base table, if the with check option clause is used in the defined view, the insert operation cannot be performed on The View.
Note: The non-code reserved table is interpreted as follows:
In Dept, dept_no indicates the master code, and in EMP, emp_no indicates the master code.
Create a connection View:
Create view emp_dept
Select EMP. emp_no, EMP. emp_name, EMP. dept_no, Dept. Name
From EMP, Dept
Where EMP. dept_no = Dept. dept_no

In this view, emp_no still acts as the primary code, so EMP retains the table for the code, and dept_no in dept is not the primary code, so it retains the table for the non-code.

Insert data to the view after joining multiple tables. We recommend that you use an alternative trigger.

Create trigger [Trigger name]
On [view name]
Instead of insert
As
Begin
-- Declare variables;
-- Find the data of all columns from the inserted Table and assign them to declared variables respectively;

-- Use the above data to insert data to the first table
-- Use the above data to insert data to the second table
End

In addition, the user_updatable_columns table can be used to query whether the table or view can be updated.

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.