Oracle例外 视图
一:例外的分类:预定义例外、非预定义例外、自定义例外
1.预定义例外
declare
v_ename emp.ename%type;
begin
    select ename into v_ename from emp where empno=&no;
dbms_output.put_line(‘名字:'|| v_ename);
//做例外处理, 如不处理,如果编号不存在,则抛错
exception
    when no_data_found then
    dbms_output.put_line('编号不存在');
end;
/

常见的例外有:case_not_found, cursor_already_open, dup_val_on_index, invalid_cursor, invalid_number,no_data_found, too_many_rows, zero_divide, value_error

2. 非预定义例外

3. 自定义例外
create or replace procedure ex_test(spNo number) is
--定义一个例外
myex exception;
begin
--更新用户sal
    update emp set sal=sal+1000 where empno=spNo;
    if sql%nofound then
        raise myex;
    end if
    exception
    when myex then
    dbms_output.put_line('没有更新任何用户');
end;
/

二:视图
存储起来的查询语句, 可以精确的控制权限、通过查询一个视图取多个表中的信息、 提高安全性等,但不能添加索引。 它的数据不是真正存在, 而是做了映射, 查询视图的视图再去取实际的内容。
create view myView as select sal from emp where sal < 1000;

--用dba用户去查询scott里面的emp表和dept表里面的员工号、员工名字、部门名称
create  or replace view myview1 as select e.empno, e.ename, d.dname from scott.emp e, scott.dept d where e.deptno=d.deptno order by e.empno;

--查询视图
select * from myview1;

添加只读权限:with read only
create    or replace view myview1 as select e.empno, e.ename, d.dname from scott.emp e, scott.dept d where e.deptno=d.deptno order by e.empno with read only;

删除视图:
drop view myview1;

同时,视图之间也可以做联合查询,功能非常的强大