标签:分组 with user select long sel subquery ann row
创建视图就是给查询语句取一个名称(别名)
类型:
1、简单视图 simple view
2、复杂视图 complex view
CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
[(alias[, alias]...)]
AS subquery
[WITH CHECK OPTION [CONSTRAINT constraint]]
[WITH READ ONLY [CONSTRAINT constraint]];
简单视图 simple view
示例:
create view empv80
as
select salary
from employees
where department=80;
desc empv80;
select * from empv80;
CREATE VIEW salvu50
AS
SELECT employee_id ID_NUMBER, last_name NAME,
salary*12 ANN_SALARY
FROM employees
WHERE department_id = 50;
复杂视图 complex view
CREATE OR REPLACE VIEW empvu80
(id_number, name, sal, department_id)
AS SELECT employee_id, first_name || ‘ ‘
|| last_name, salary, department_id
FROM employees
WHERE department_id = 80;
CREATE OR REPLACE VIEW dept_sum_vu
(name, minsal, maxsal, avgsal)
AS SELECT d.department_name, MIN(e.salary),
MAX(e.salary),AVG(e.salary)
FROM employees e JOIN departments d
USING (department_id)
GROUP BY d.department_name;
此select 语句复杂些,可包含函数等
DESCRIBE user_views;
SELECT view_name FROM user_views;
SELECT text FROM user_views
WHERE view_name = ‘EMP_DETAILS_VIEW‘;
set long 9999;
select 子句有表达式或者数字时,要加别名。
不能删除视图,比如有:
1、group by
2、distinct
3、rownum
4、分组函数
You can usually perform DML operations on simple views.
You cannot remove a row if the view contains the following:
1、Group functions
2、A GROUP BY clause
3、The DISTINCT keyword
4、The pseudocolumn ROWNUM keyword
标签:分组 with user select long sel subquery ann row
原文地址:http://blog.51cto.com/3938853/2157133