Note:-Please comment and reply me.
It contain detail about all language and oracle. Checkout stackoverflow profile :- http://stackoverflow.com/users/995197/sushant
CREATE VIEW statement that contains the OR REPLACE option. This option replaces the current definition of a view, but preserves the present security authorizations.ACCOUNTS_STAFF view, as given in a previous example. You also grant several object privileges to roles and other users. However, now you realize that you must redefine the ACCOUNTS_STAFF view to correct the department number specified in the WHERE clause of the defining query, because it should have been 30. To preserve the grants of object privileges that you have made, you can replace the current version of the ACCOUNTS_STAFF view with the following statement:CREATE OR REPLACE VIEW Accounts_staff AS
SELECT Empno, Ename, Deptno
FROM Emp
WHERE Deptno = 30
WITH CHECK OPTION CONSTRAINT ica_Accounts_cnst;
WITH CHECK OPTION for a view's definition is dropped.EMP table using the ACCOUNTS_STAFFview:INSERT INTO Accounts_staff
VALUES (199, 'ABID', 30);
SET or DISTINCT operators, a GROUP BY clause, or a group function, then rows cannot be inserted into, updated in, or deleted from the base tables using the view.WITH CHECK OPTION, then a row cannot be inserted into, or updated in, the base table (using the view), if the view cannot select the row from the base table.NOT NULL column that does not have a DEFAULT clause is omitted from the view, then a row cannot be inserted into the base table using the view.DECODE(deptno, 10, "SALES", ...), then rows cannot be inserted into or updated in the base table using the view.WITH CHECK OPTION of the ACCOUNTS_STAFF view only allows rows that have a department number of 10 to be inserted into, or updated in, the EMP table. Alternatively, assume that the ACCOUNTS_STAFF view is defined by the following statement (that is, excluding the DEPTNO column):CREATE VIEW Accounts_staff AS SELECT Empno, Ename FROM Emp WHERE Deptno = 10 WITH CHECK OPTION CONSTRAINT ica_Accounts_cnst;
EMPNO or ENAME fields of existing records, but you cannot insert rows into the EMP table through the ACCOUNTS_STAFF view because the view does not let you alter the DEPTNO field. If you had defined a DEFAULT value of 10 on the DEPTNO field, then you could perform inserts.
CREATE VIEW accounts_staff AS SELECT Empno, Ename, Deptno FROM Emp WHERE Deptno = 10 WITH CHECK OPTION CONSTRAINT ica_Accounts_cnst;Now to see the account people you don’t have to give a query with where condition you can just type the following query. Select * from accounts_staff;Select sum(sal) from accounst_staff;Select max(sal) from accounts_staff; As you can see how views make things easier.ACCOUNTS_STAFF view references only rows in department 10. Furthermore, WITH CHECK OPTION creates the view with the constraint that INSERT and UPDATEstatements issued against the view are not allowed to create or result in rows that the view cannot select.INSERT statement successfully inserts a row into the EMP table through the ACCOUNTS_STAFF view:INSERT INTO Accounts_staff VALUES (110, 'ASHI', 10);
INSERT statement is rolled back and returns an error because it attempts to insert a row for department number 30, which could not be selected using theACCOUNTS_STAFF view:INSERT INTO Accounts_staff VALUES (111, 'SAMI', 30);
SELECT *
FROM ( SELECT deptno, count(*) emp_count
FROM emp
GROUP BY deptno ) emp,
dept
WHERE dept.deptno = emp.deptno;
SELECT a.last_name, a.salary, a.department_id, b.maxsal
FROM employees a,
( SELECT department_id, max(salary) maxsal
FROM employees
GROUP BY department_id ) b
WHERE a.department_id = b.department_id
AND a.salary = b.maxsal;