Translate

VIEWS in ORACLE

What are different Types of Views in ORACLE? What is the difference between Simple View and Complex View?
  • View is a virtual table that does not physically exist. Rather, it is created by a query joining one or more tables. A view contains no data itself.
  •  A view is simply any SELECT query that has been given a name and saved in the database.  For this reason, a view is sometimes called a named query or a stored query.
Benefits of using Views
  • Commonality of code being used. Since a view is based on one common set of SQL, this means that when it is called it’s less likely to require parsing.
  • Security. Views have long been used to hide the tables that actually contain the data you are querying. Also, views can be used to restrict the columns that a given user has access to.
The syntax for the CREATE VIEW Statement in Oracle/PLSQL is:
CREATE VIEW View_Name AS
  SELECT columns
  FROM tables
  [WHERE conditions];

Feature
Simple Views
Complex Views
Number of tables
One
One or more
Contain functions
No
Yes
Contain groups of data
No
Yes
DML operations through a view
Yes
Not always

Simple Views

·       A view takes the output of a query and makes it appear like a virtual table. You can use a view in most places where a table can be used.
·       All operations performed on a view will affect data in the base table and so are subject to the integrity constraints and triggers of the base table.
·       A View can be used to simplify SQL statements for the user or to isolate an application from any future change to the base table definition. A View can also be used to improve security by restricting access to a predetermined set of rows or columns.
·       In addition to operating on base tables, one View can be based on another, a view can also JOIN a view with a table (GROUP BY or UNION).
·       Using views encourages the use of Shared SQL with the benefit of reduced memory usage.

Create View Employee_Det As
Select E.Empno, 
         E.ename,E.sal,E.deptno,D.dname,D.loc
        From Employee E, Dept D
        Where E.deptno=D.deptno;

Materialized Views

·       Materialized views are schema objects that can be used to summarize, Precompute, replicate, and distribute data. E.g. to construct a data warehouse.
·       A materialized view provides indirect access to table data by storing the results of a query in a separate schema object. Unlike an ordinary view, which does not take up any storage space or contain any data.
·       The existence of a materialized view is transparent to SQL, but when used for query rewrites will improve the performance of SQL execution. An updatable materialized view lets you insert, update, and delete.
·       You can define a materialized view on a base table, partitioned table or view and you can define indexes on a materialized view.
·       Materialized views stored in the same database as their base tables can improve query performance through query rewrites. Query rewrites are particularly useful in a data warehouse environment.
·       A materialized view log is a schema object that records changes to a master table's data so that a materialized view defined on the master table can be refreshed incrementally.

 Basic Syntax

CREATE MATERIALIZED VIEW view-name
BUILD [IMMEDIATE | DEFERRED]
REFRESH [FAST | COMPLETE | FORCE ]
ON [COMMIT | DEMAND ]
[[ENABLE | DISABLE] QUERY REWRITE]
[ON PREBUILT TABLE]
AS
SELECT <Query>;
The BUILD clause options are shown below.
  • IMMEDIATE : The materialized view is populated immediately.
  • DEFERRED : The materialized view is populated on the first requested refresh.
The following refresh types are available.
  • FAST : A fast refresh is attempted(M View Log File). If materialized view logs are not present against the source tables in advance, the creation fails.
  • COMPLETE : The table segment supporting the materialized view is truncated and repopulated completely using the associated query.
  • FORCE : A fast refresh is attempted. If one is not possible a complete refresh is performed.
A refresh can be triggered in one of two ways.
  • ON COMMIT : The refresh is triggered by a committed data change in one of the dependent tables.
  • ON DEMAND : The refresh is initiated by a manual request or a scheduled task.
The QUERY REWRITE clause tells the optimizer if the materialized view should be consider for query rewrite operations. An example of the query rewrite functionality is shown below.
The ON PREBUILT TABLE clause tells the database to use an existing table segment, which must have the same name as the materialized view and support the same column structure as the query.
A materialized view can be manually refreshed using the DBMS_MVIEW package.
EXEC DBMS_MVIEW.refresh('EMP_MV');


Let’s Understand this Practically
Create a Normal and Materialized View with the below Created Table – 
SQL> SELECT * FROM VTAB;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 RAVI               50
       112 PANKAJ             40
       110 SAJAL              10
       106 TIRATH             40
Normal View and Materialized View
SQL> CREATE VIEW V AS SELECT * FROM VTAB;

View created.

SQL> SELECT * FROM V;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 RAVI               50
       112 PANKAJ             40
       110 SAJAL              10
       106 TIRATH             40
/*Now Create aMaterialized View(Make sure you have Privilege to do the same)*/
SQL> CREATE MATERIALIZED VIEW MV
  2  AS SELECT * FROM VTAB;

Materialized view created.

SQL> SELECT * FROM MV;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 RAVI               50
       112 PANKAJ             40
       110 SAJAL              10
       106 TIRATH             40

Unlike views, however, materialized views also store the results of the query in the database. In the following screen note how the ROWID's for the table and the view are identical, indicating the view returns the exact same data stored in the table. The ROWID’s of the materialized view, on the other hand, differ from those of the table. This indicates the materialized view is returning a physically separate copy of the table data.

SQL> SELECT ROWID FROM VTAB;

ROWID
------------------
AAASi7AAEAAAANbAAB
AAASi7AAEAAAANbAAC
AAASi7AAEAAAANbAAD
AAASi7AAEAAAANcAAA
/*ROWID Will be same in case of NORMAL VIEW*/
SQL> SELECT ROWID FROM V;

ROWID
------------------
AAASi7AAEAAAANbAAB
AAASi7AAEAAAANbAAC
AAASi7AAEAAAANbAAD
AAASi7AAEAAAANcAAA
/*ROWID Will be different in case of MVIEW as it Creates a separate physical Copy*/
SQL> SELECT ROWID FROM MV;

ROWID
------------------
AAAS8uAAEAAAANLAAA
AAAS8uAAEAAAANLAAB
AAAS8uAAEAAAANLAAC
AAAS8uAAEAAAANLAAD
The difference between views and materialized views becomes even more evident than this when table data is updated.

SQL> UPDATE VTAB SET NAME=LOWER(NAME);

4 rows updated.

SQL> SELECT * FROM VTAB;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 ravi               50
       112 pankaj             40
       110 sajal              10
       106 tirath             40

SQL> /*Now Select Records From Normal View*/
SQL> SELECT * FROM V;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 ravi               50
       112 pankaj             40
       110 sajal              10
       106 tirath             40

SQL> /*Now check the data in MView*/
SQL> SELECT * FROM MV;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 RAVI               50
       112 PANKAJ             40
       110 SAJAL              10
       106 TIRATH             40

Note how, after the update, the view data matches the table data but the materialized view data does not. Data in materialized views must be refreshed to keep it synchronized with its base table. Refreshing can either be done manually, as below, or automatically by Oracle in some cases.


Execute Dbms_Mview.Refresh('MV');

SQL> SELECT * FROM MV;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 RAVI               50
       112 PANKAJ             40
       110 SAJAL              10
       106 TIRATH             40

SQL> EXECUTE DBMS_MVIEW.REFRESH('MV');

PL/SQL procedure successfully completed.

SQL> --Now Check the Data in MVIEW
SQL> SELECT * FROM MV;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 ravi               50
       112 pankaj             40
       110 sajal              10
       106 tirath             40

SQL> SELECT * FROM VTAB;

        ID NAME           DEPTNO
---------- ---------- ----------
       101 ravi               50
       112 pankaj             40
       110 sajal              10
       106 tirath             40

Now that the materialized view has been refreshed its data matches that of its base table.


Difference between View and Materialized View in database

  • Views query result is not stored in the disk or database but Materialized view allow to store query result in disk or table.
  • When we create view using any table, ROWID of view is same as original table but in case of Materialized view ROWID is different.
  • In case of View we always get latest data but in case of Materialized view we need to refresh the view for getting latest data.
  • Performance of View is less than Materialized view.
  • In case of view its only the logical view of table no separate copy of table but in case of Materialized view we get physically separate copy of table.
  • In case of Materialized view we need extra trigger or some automatic method so that we can keep MV refreshed, this is not required for views in database.


                                   View                                         
                Materialized View                   

View will not store any data- It's just a stored Query which will fetch data from its Base Table
M-View will store data in Table segment.
Views are virtual only and run the query definition each time they are accessed.

Materialized views are disk based and are updated periodically based upon the query definition.
View is mainly used for Security purpose.

M-view is used for Performance improvement.

Whenever Base table is dropped the View will become inaccessible.

Whenever Base table is dropped the M-View will still be accessible.

We can perform DML operations directly on View.

We can't perform DML operations.



Get involved and leave your Comments in the Box Below. The more people get involved, the more we all benefit.
So, leave your thoughts before you leave the page. 

66 comments:

  1. Really nice blog, very infromative. You can refer more topics related to SQL like SQL Commands and Advanced SQL from here for future articles
    thanks !

    ReplyDelete
  2. Fritz box router allows speedy and stable internet connection. It can be connected as wired or wireless also. For a wired connection, you have to use an ethernet cable and connect it with your router. Get detailed information from http://fritz.box. There is all information regarding this product is given.

    ReplyDelete
  3. Find synology has a big storage. You can easily store data like images, videos, documents etc in rs820+. You can access find.synology.nas anywhere or anytime by using a username and password.

    ReplyDelete
  4. Someone facing linksys unexpected error 2123 and they need to resolve this. The issue will be resolved easily but user need to get an advanced information. They want to make this step by step.

    ReplyDelete
  5. To need dlink router login and setup you can get it from http //dlinkrouter.local web based login. Sometimes you need to add an extender and want to need a step for making this. Here you can get everything that you want.

    ReplyDelete
  6. Thanks for this blog. Very informative. speedefywifi router allows speedy internet connection. Get the speedefy ac2100 review from here.

    ReplyDelete
  7. Linksys router provides high-speed internet connection. With myrouter local setup you can easily connect more than twenty devices at one time. Get detailed information from cisco linksys e1500 here.

    ReplyDelete
  8. Edimax extender helps to extend the range of a router. edimax br 6478ac v2 covers wide areas with an internet connection. If there is any problem with edimaxext. You can contact our experts.

    ReplyDelete
  9. If you wanna that your router covers wide areas with an internet connection. Then, you have to connect a tplinkrepeater with your router. Get complete deco m4 setup guidence from here.

    ReplyDelete
  10. You can get rockspace_ext details with using rockspace.local web utility. If want advanced details and information then you need to read the manuals.

    ReplyDelete
  11. If you need to login extender device then first of all type 192.168.10.1 IP address in the web browsen. Then you face a login interface and try to login with username and password.

    ReplyDelete
  12. Easily get netgear eax20 setup with using IP login and troubleshoot the issue with Update process. If you need to get reset process then simply press the reset button. Also available 192.168.1.250 IP address for login.

    ReplyDelete
  13. Do you wanna complete a setup with the mercusys router? You can easily complete a configuration just need to open the admin login panel of mwlogin net. After that, you can easily log in with ac12g default password and username. After login, you can change the settings according to your need.

    ReplyDelete
  14. Searching for a router? tplinkwifi.net router is the best option for you. It allows high-speed internet connection. Get the tplink archer ax11000 review from here.

    ReplyDelete
  15. Amplifi wifi system is the one that allows a wide range of high-speed internet connections. With amplifi alien It can be connected as wired or wireless also.

    ReplyDelete
  16. In order to complete the canon ts6420 setup need to follow the manual instructions of your canon printer, for any kind of help can get connected with our experts.

    ReplyDelete
  17. Get detailed information from repeater.asus. For detailed information need to read the manual.

    ReplyDelete
  18. Thanks for sharing this blog. If you are interested to learn the dance steps. You can join the dance classes in ambala. Hip-Hop, classical, Kathak classes are also given here.

    ReplyDelete
  19. In order to complete zumimal camera setup can download the zumimall camera app from the playstore.

    ReplyDelete
  20. Read the d'link ax1800 review before buying this product, Here you will get all the details.

    ReplyDelete
  21. In order to complete the deco p9 powerline setup need to access the administration login panel. By typing the default IP Address tplinkdeco net in the URL box. It will takes you to the admin login page.

    ReplyDelete
  22. If you like to listen to music and search for the lyrics of a song. You can get hindi songs lyrics from here.

    ReplyDelete
  23. Rockspace extender has internet connection with wide range and super fast connectivity. Through WPS can setup easily. use re.rockspace.local to configure.

    ReplyDelete
  24. Belkin wireless range extender allows a high speed connection, in order to complete the setup type belkin.range in the URL box it will takes you to the admin page.

    ReplyDelete
  25. To complete the rangextd Booster setup. Type the default IP Address in the URL box, It will takes you to the admin login page.

    ReplyDelete
  26. Netgear AC1750 Range Extender Setup | AC1750 firmware update

    Range Extender Setup

    ReplyDelete
  27. Download Quick VPN Mod Apk with its fantastic features including high privacy, full security, no ads and enter into 11 countries' location.
    https://apkchew.com/quick-vpn/

    ReplyDelete
  28. Disney Plus clients can utilize the Disneyplus.com Begin accessible on your TV to determine the Disneyplus.com login/begin issue. Here in this article to actuate Disney Plus on your gadget, you can look through how to enter Disney Plus.Com Start 8-digit code.

    ReplyDelete
  29. Cord cutters have long been able to watch local news stations by using antennas and free over-the-air broadcasts.But for cable news networks like Foxnews.com/connect (or CNN, MSNBC, and the rest of the gang), that won't work.There is a solution,though, and it's called a skinny bundle.Skinny bundles are exactly what they sound like: pay-TV packages that cut the fat by eliminating some of cable and satellite's less-watched channels and delivering a slimmed-down selection for a slimmed-down price.

    ReplyDelete
  30. Thanks for taking the time to discuss and share this with us, I for one feel strongly about it and really enjoyed learning more about this topic. I can see that you possess a degree of expertise on this subject, I would very much like to hear much more from you on this subject matter – I have bookmarked this page and will return soon to hear additional information about it. There are certainly impressive stories. Passion for sharing your website with us. You’re doing a great job Man, Keep it up.
    https://disneyplus.beginpluss.com
    https://disney.plus1begin.com/
    https://disney.plus2begin.com
    https://disneyplusbegin-code.com
    https://disneyplusstartcode.com/
    https://begin-disneyplus.com/

    ReplyDelete
  31. "It is great blog post. I am Always read your blog. Helpful and Informative blog. Thanks for sharing these information with us.

    Cricut Setup Windows
    Cricut.com/Setup"

    ReplyDelete
  32. In larger areas wireless transmission is required, re.rockspace local wifi extender function as a repeater to boost the signal and fend off it from dead zone area. Primarily, re.rockspace local wifi extender works at 2.4G band thereby providing full signal coverage with transference speed of 300 Mbps. Also, ROCKSPACE ROUTER AC2100 is there that works at dual band and boost your home network by increasing the range and speed of wifi signal.

    ReplyDelete
  33. re.rockspace local is an Independent technical support Service provider. The product names used in this web site are for identification purposes only. All trademarks and registered trademarks are the property of their respective owners. re.rockspace local has no affiliation or certification with any of company unless such bond is expressly specified. The ROCKSPACE ROUTER AC2100 is designed for high-traffic environments. The design of the router reveals a lot about the router’s owner.

    ReplyDelete
  34. Disney plus is a streaming platform that is similar as Hulu, Netflix, and Amazon Prime Video. There's plenty of programming from Pixar, Marvel Studios, and the Star Wars world, in addition to Disney is the most popular subscription channels in the world. It has grown increasingly popular throughout the globe. There is a comprehensive listing of Disney classics and your new favourite Disney films. Disneyplus.com/begin - is a one-stop shop for all of your favorite Disney shows and movies. The software is famous for its software to stream video. This service lets you stream live television shows, sports as well as videos.

    ReplyDelete
  35. Plex is an amazing app with which you can easily manage the media storage and can easily access it from multiple devices. Nowadays, everyone has different choices of TV choices, movies and other entertainment shows that make it too difficult to manage these files. If you’re in search of an online server specifically designed for streaming videos, films, and media files, you’re on the right track since Plex offers all of these services. Plex plays a great role in offering effective solutions to resolve this issue. It offers the option with which the user can access the media files from any of the compatible devices without transferring any file. You just need to enter plex tv code and activate Plex.tv/link and after that you can enjoy the features of Plex.

    ReplyDelete
  36. This is very good blog post, I like the way you pointed all stuff, must follow below useful link.
    plex.tv/link

    ReplyDelete
  37. I was truly satisfied to track down this page. I expected to thank you for ones time for this stunning read!! I clearly preferred every single piece of it and I have you saved to fav to see new data in your blog. daily tech

    ReplyDelete

  38. APKNIKE provides Free Apps and games for android APK An application file ready for installation
    in an Android device. The compressed APK file, which is a ZIP archive in the JAR format

    Real Gangster Crime Mod APK

    ReplyDelete
  39. This article is very good, your blog is also very good : I read all articles and words and always get to learn something from it, its helpfulu for us thank you very much for sending this article to me.

    ReplyDelete
  40. Vidmix APK is a video editing app for music videos. Users can create their own style of videos using Vidmix APK

    ReplyDelete
  41. If you are facing the Nest camera going offline, then you need to check the power supply. For the Nest camera to work effectively, it requires a stable source of power. You need to plug the camera into a working outlet. It also requires a proper wifi connection. You need to install it near the router to ensure a flawless internet connection.

    ReplyDelete
  42. This comment has been removed by the author.

    ReplyDelete
  43. Are you having trouble logging in to your Linksys router? Not sure where to start? Don't worry, we're here to help! First, make sure your computer or device is connected to the same network as your router. For next steps, and learn how to login to linksys router in easy methods

    ReplyDelete
  44. You might not make the most out of your range extender even after performing Netgear EX6110 setup

    ReplyDelete
  45. The reason being, technical glitches are one of the biggest causes contributing to “Netgear Orbi red light” issue.

    ReplyDelete
  46. This blog is very useful content. Thanks for sharing
    Linksys router login ip

    ReplyDelete
  47. LINKSYS EXTENDER RESET
    Linksys WiFi range extender is one of the most preferred networking device to get an extended WiFi network in every square inch of the home.

    ReplyDelete
  48. If the Wavlink extender IP address is not working for you, then there is a possibility that you’re committing a typing error during its entry. However, if that’s not the case, then try to access the range extender’s dashboard via the http //wifi.wavlink.com setup URL. Are you able to? No? Well, this post is intended to resolve the issue you are facing with your range extender i.e. Wavlink extender IP address not working. Walk through the points mentioned below and learn how to fix the problem.

    ReplyDelete
  49. While you are trying to access the admin panel of the Netgear WiFi router, you need to use routerlogin.net web address. The admin panel is accessed to manage your Netgear router settings. But if are unable to access it due to any reason then it can be troublesome. Is there a way you can fix this issue? Yes, there is. You can easily fix it! How? By using the instructions highlighted in this article.

    ReplyDelete
  50. Thank you so much. Such an amazing content, keep sharing more. A million users have done Wavlink WiFi extender setup with this hope that they will get high-speed internet range to access everywhere in their homes. However, nowadays, 4 out of 5 users are reporting that they are unable to make the most out of their Wavlink extenders because of the “Wavlink extender not getting full speed” issue.

    ReplyDelete
  51. Linksys Velop Setup Using Manual Method
    This is also known as Linksys smart WiFi setup method. In this, you need to access Linksys router login page using linksyssmartwifi.com web address.

    ReplyDelete
  52. Great work! thank you for posting this amazing blog. are you facing issues while logging into your Amped wireless range extender ? And, due to this error, you are unable to setup Amped wireless extender? First of all, relax your senses and know that this issue isn’t worth stressing over. Really, if you implement the fixes provided in this piece of writing, the issue can be fixed easily in a short span of time.

    ReplyDelete
  53. This post is exactly what I needed to read today! Your words about self-care and self-love are so important, yet so easy to overlook in the hustle and bustle of daily life. Your message about treating ourselves with compassion and kindness is a powerful reminder that we are worthy of love and care, both from ourselves and from others. Thank you for spreading positivity and inspiration. same as well could you read it ayothi web series

    ReplyDelete
  54. This comment has been removed by the author.

    ReplyDelete
  55. This comment has been removed by the author.

    ReplyDelete
  56. It is recommended that you consider setting up your Netgear router by accessing the Netgear Nighthawk router setup wizard.

    ReplyDelete
  57. Thank you for this SQL Database Post, Keep Sharing.
    Also visit our Website Adarsh Park Garden and Provident Ecopolitan

    ReplyDelete
  58. fritzbox login erweitert die Reichweite eines Routers. Es deckt weite Gebiete mit einer Internetverbindung ab. Durch die Verwendung von 192.168.178.1 können Sie problemlos an Ihren Online-Kursen, Geschäftsarbeiten, Besprechungen usw. teilnehmen.
    fritzbox 7490 login

    ReplyDelete
  59. Wenn Sie nach einer Hochgeschwindigkeits-Internetverbindung suchen. Anschließend müssen Sie eine Verbindung zur fritz.box login herstellen. Weil es eine schnelle Internetverbindung ermöglicht. fritzbox 7490 login

    ReplyDelete
  60. Thanks for sharing the informative content with us. Access your www.arcor.de login account effortlessly with arcor login.

    ReplyDelete
  61. what i do not comprehended is as a widespread rule the way you aren't virtually much more all round liked than you may be at the prevailing time. You're smart. You spot consequently basically concerning //totojijon-64.webselfsite.net/">토토지존검증사이트

    ReplyDelete
  62. then this guide will be of great help to you. So, read on to know different methods to do Wavlink setup.

    ReplyDelete
  63. Great article! Thanks for sharing your knowledge. I have shared a post on the Rockspace_ext topic. Just click on the link to read.

    ReplyDelete