1.创建视图:

SQL> create view empvu80 as 
  2  select employee_id,last_name,salary
  3  from employees
  4  where department_id = 80;

View created.

SQL> desc empvu80
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPLOYEE_ID                               NOT NULL NUMBER(6)
 LAST_NAME                                 NOT NULL VARCHAR2(25)
 SALARY                                             NUMBER(8,2)

2.在子查询中使用别名创建视图:

SQL> create view salvu50 as 
  2  select employee_id id_number,last_name name,salary*12 ann_salary
  3  from employees
  4  where department_id = 50;

View created.

3.使用CREATE OR REPLACE VIEW 子句修改EMPVU80视图。为每一列都增加别名:

SQL> create or replace view empvu80
  2  (id_number,name,sal,department_id)
  3  as select employee_id,first_name ||''||last_name,salary,department_id
  4  from employees
  5  where department_id = 80;

View created.

4.创建复杂视图,包含一个组函数:

SQL> create or replace view dept_sum_vu (name,minsal,maxsal,avgsal) as
  2  select d.department_name,min(e.salary),max(e.salary),avg(e.salary)
  3  from employees e join departments d
  4  on (e.department_id = d.department_id)
  5  group by d.department_name;

View created.

5.使用 WITH CHECK OPTION 子句确保DML只能在特定的范围内执行:

SQL> create or replace view empvu20 as 
  2  select * from employees
  3  where department_id = 20
  4  with check option constraint empvu20_ck;

View created.

6.创建序列:

SQL> create sequence dept_deptid_seq
  2  increment by 10
  3  start with 120
  4  maxvalue 9999
  5  nocache
  6  nocycle;

Sequence created.

7.修改序列:

SQL> alter sequence dept_deptid_seq
  2  increment by 20
  3  maxvalue 999999
  4  nocache
  5  nocycle;

Sequence altered.

8.创建索引:

SQL> create index emp_last_name_idx
  2  on employees(last_name);

Index created.

9.创建和删除同义词:

SQL> create synonym d_sum for dept_sum_vu;

Synonym created.

SQL> drop synonym d_sum;

Synonym dropped.

 

posted on 2016-11-17 22:27  Tomatoes  阅读(170)  评论(0编辑  收藏  举报