pl/sql例外处理
例 当输入编号没有时的例外处理
declare
--定义
v_ename emp.ename%type;
begin
--
select ename into v_ename from emp where empno = &gno;
dbms.output.put_line('名字:'||v_ename);
exception
when no_data_found then
dbms_output.put_line('编号没有!');
end;
--自定义例外
create or replace procedure ex_test(spNo number)
is
--定义例外
myexcep exception;
begin
--更新
update emp set sal = sal + where empno = spNo; --sql%notfound这是表示没有update
--raise myexcep 触发myexcep if sql%notfound then
raise myexcep;
end if;
exception
when myexcep then
dbms_output.put_line('没有update'); end;
oracle视图
视图是一个虚拟表,其内容由查询定义,同真实的表一样,视图包含一系列带有名称的列和行数据,但是,视图并不在
数据库中以存储的数据值集形式存在,行和列数据来*定义视图的查询所引用的表,并且在引用视图时动态生成。
表需要占用磁盘空间,视图不需要
视图不能添加索引
使用视图可以简化复杂查询
创建视图
create view myview as select * from emp where sal<;
使用视图
select * from myview;
利用视图简化操作
create view myview2 as select emp.deptno,emp.name,dept.deptno from emp,dept where emp.deptno =
dept.deptno;
select * from myview2;