Oracle Create View Method: Syntax & Example
The method for creating a view in Oracle database is as follows:
- A view can be created using the CREATE VIEW statement with the following syntax.
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
- Create a view called employee_view which displays the id, name, and salary fields from the employee table.
CREATE VIEW employee_view AS
SELECT id, name, salary
FROM employee;
- When creating views, you can manipulate and filter data using aliases, calculated fields, aggregate functions, and more.
- After creating the view, you can retrieve data by querying the view using the SELECT statement, just like querying a regular table.
SELECT * FROM employee_view;
- You can use the ALTER VIEW statement to change the definition of a view, and use the DROP VIEW statement to delete a view.