您的位置:首页 > 数据库 > Oracle

oracle数据库例外处理与视图

2016-09-17 20:12 555 查看
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 + 1000 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<1000;
使用视图
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: