zoukankan      html  css  js  c++  java
  • oracle数据库例外处理与视图

    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;
  • 相关阅读:
    14-Reverse Integer
    13.Merge k Sorted Lists
    12-Add Digits
    11-String to Integer (atoi)
    10.Power of Two-Leetcode
    9. Delete Node in a Linked List
    使用Openmp并行化
    C++编译过程与内存空间
    C++栈溢出
    程序(进程)内存空间分布深入理解
  • 原文地址:https://www.cnblogs.com/dongzhuangdian/p/5879547.html
Copyright © 2011-2022 走看看