Can views in Oracle be updated?
If I make such a survey on the internet, I think many netizens and friends will answer this question without thinking about it. No, the view is a logical record, not a physical record, in addition, many of my friends have such a subconscious influence or experience.
However, here I want to tell you that views can be updated. However, this is not a common view.
The following views can be updated:
1. The view field only involves one table.
2. If multiple tables are involved, the table column mapped to the View column (or the combination of columns) must be subject to the primary constraint.
3. Force Execution by adding hint/* + bypass_ujvc */
Let's do an experiment, OS Window XP regression Sion, Oracle 10.2.0.1
CREATE TABLE test1 ( id integer primary key, num integer ); INSERT INTO test1 VALUES (1,0); INSERT INTO test1 VALUES (2,0); CREATE TABLE test2 ( id integer, num integer, upd integer ); INSERT INTO test2 VALUES (1,10, 0); INSERT INTO test2 VALUES (2,20, 1);
UPDATE ( SELECT t1.id id1, t1.num num1, t2.id id2, t2.num num2 FROM test1 t1, test2 t2 WHERE t1.id=t2.id AND t2.upd=1) SET num1=num2;ORA-01779: cannot modify a column which maps to a non key-preserved table
CREATE UNIQUE INDEX test2_idx_001 ON test2 (id); UPDATE ( SELECT t1.id id1, t1.num num1, t2.id id2, t2.num num2 FROM test1 t1, test2 t2 WHERE t1.id=t2.id AND t2.upd=1) SET num1=num2;1 row updated. UPDATE ( SELECT /*+ BYPASS_UJVC */t1.id id1, t1.num num1, t2.id id2, t2.num num2 FROM test1 t1, test2 t2 WHERE t1.id=t2.id AND t2.upd=1) SET num1=num2;
We can see that not all views can be updated through the experiment here. Sometimes our subconscious and experience are very helpful for our learning,
Sometimes this kind of superficial meaning and experience have some bad effects on our learning. It is a good habit of learning and a lot of solidified ideas, it is not necessarily true. If you have a solid learning experience and don't let go of any questions in your learning, you can learn to be a correct and rebellious person.