码迷,mamicode.com
首页 > 数据库 > 详细

Oracle_071_lesson_p14

时间:2018-08-10 12:25:47      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:分组   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

Oracle_071_lesson_p14

标签:分组   with   user   select   long   sel   subquery   ann   row   

原文地址:http://blog.51cto.com/3938853/2157133

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!