1. What is the View?
2. What is Simple view and Complex view ?
3. What is Materialized view ?
Example :
- Create 2 views : normal and materialized view
- Now if we DELETE data in table emp, then the normal view is empty, but the m-view still remains data.
- To refresh m-view, we could use âdbms_mview.refresh(âmview_jobhis_50â)â
4. FORCE keyword
- If we create a view on a table which doesnât exist yet, then itâll throw an error. In a few scenarios, we still want to create a view, because the underlying table will be created later, so we donât want to bother about the order of object creation, so we could use FORCE view option.
- For checking if the view is created sucessfully, we can check in tables âuser_viewsâ and âuser_objectsâ
- We see that the view is created sucessfully, but itâs INVALID status. If we try to query this view, weâll receive the error because the underlying table doesnât exist.
- Now, if we create a table and insert some data into table then commit. Then the view will become VALID and we can query on it now.
5. WITH READ ONLY keyword
As you might know, itâs possible to do DML on simple view. In case you donât want this, you can disable it by using âWITH READ ONLYâ keyword.
6. WITH CHECK OPTION keyword
If you want to restrict the view to DML on a specific data only, then you could use âWITH CHECK OPTIONâ keyword.
7. Constraint of view
- Optionally, you can specify âconstraintâ name. If you donât specify a constraint name, Oracle will by default create a system generated constraint name.
- You can specify constraint names when create a view, and make sure that constraint names are unique, else youâll receive the error.
Additional notes
1. Write a procedure to create a view for all tables in the given schema. The view name should be table name + â_Vâ
2. Oracle View related questions
Q1 : No, the moment we create the view with the â*â, Oracle will replace the â*â with available columns at that time only. You can check it in the dictionary table âuser_viewsâ
Q2 : The view will face error
Q3 : using dictionary table âuser_dependenciesâ
3. Oracle View related questions
Q1 : for example, when we drop the column in base table, then thew view will be invalid.
If we re-create the column again, the view wonât be VALID automatically, so we need to recompile it.
There are 3 options to recompile : alter view, re-creating the view or just simply query on the view
NOTE
When the view is INVALID, but we donât recompile the view. Instead, we call directly the view which in INVALID state, then Oracle will automatically try to recompile it at the first execution. Then if the recompile is succesfully, the the view is back to VALID. In case of the compile error, then itâll throw an error.
Q2 : The same with Q1, we have 3 options to recompile the force view
Q3 : for example, we can create all the views with forcing option, then create tables. At the end of installation, you can recompile of all invalid objects. By this way, we no need to worry about dependencies accross installation.