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;
  • 相关阅读:
    java对象转json对象
    cas-client登录后报INVALID_PROXY_CALLBACK
    tomcat启动一闪而过,调试tomcat
    获取url中的参数
    cas 退出后跳转指定页面
    cas增加验证码
    spring security+cas(cas proxy配置)
    oracle 导入导出指定表
    Marshaller根据对象生成xml文件
    webpack学习笔记
  • 原文地址:https://www.cnblogs.com/dongzhuangdian/p/5879547.html
Copyright © 2011-2022 走看看