zoukankan      html  css  js  c++  java
  • PL/SQL&存储过程||存储函数&触发器

    plsql 有点:交互式  非过程化   数据操纵能力强   自动导航语句简单   调试简单   想率高 声明类型的方式 1.基本类型 2.引用变量 3.记录型变量 基本格式 declare 声明 begin exception end 判断语句 if:。。then。。。 else end if;

    循环 loop 退出条件   exit when 。。。;

    end loop;

    光标 cursor ---resltSet 返回多行数据

    格式 cursor 表明 oper 打开 fetch 去一行光标 close 关闭

    oracle 异常处理 exception

    timeout_on_resourrce 请求超时   储存过程 储存函数 触发器 基于plsql

    储存过程 格式 create (or replace)procedure   as

    储存过程 储存函数 区别:储存函数 必须有返回值 只能接受一个参数 二储存过程 可有可无返回值  可有可无参数  并能接受多个参数   与返回值可以是集合

    可以使用光标  java调用储存过程

    1:创建数据库链接connectio 2.预编译sql对象  可以创建一个结果集 3.(使用光标) 结果集对象

    sql: String sql = "{call MYPACKAGE.queryEmpList(?,?)}";调用储存过程 是用光标 call.registerOutParameter(2, OracleTypes.CURSOR); 光标类型

    数据字典 元数据    数据库框架

     触发器:行级触发器,语句级触发器

    实例:

    /*
    实施复杂的安全性检查
    禁止在非工作时间插入新员工
    
    非工作时间:
    1. 周末: to_char(sysdate,'day') in ('星期六','星期日')
    2. 上班前 下班后:to_number(to_char(sysdate,'hh24')) not betweeen 9 and 18
    */
    create or replace trigger securityemp
    before insert
    on emp
    begin
       if to_char(sysdate,'day') in ('星期六','星期日') or
          to_number(to_char(sysdate,'hh24')) not between 9 and 18 then
             --抛出错误
             raise_application_error(-20001,'禁止在非工作时间插入新员工');
       end if;
    end;
    /
    --涨后的工资不能少于涨前的工资
    
    create or replace trigger checksal
    before update
    on emp
    for each row
    begin
    
      --if 涨后的薪水 <  涨前的薪水 then 
      if :new.sal < :old.sal then
        raise_application_error(-20002,'涨后的工资不能少于涨前的工资.涨后:'||:new.sal||'   涨前:'||:old.sal);
      end if;
    
    end;
    /
  • 相关阅读:
    THUSC2021游记
    CF补题计划
    2020 Petrozavodsk Winter Camp Day5 简要题解
    很“炸”的安卓UI自动化工具
    SQL-关联查询
    MeterSphere接口自动化平台的使用
    Android开发Handler是如何确保UI刷新优先执行的源码解读
    android开发BadTokenException: Unable to add window -- token null is not valid; is your activity running?比较好的解决方法
    Android开发判断是否为鸿蒙系统
    Android性能优化使用自带的Profiler功能分析traceView文件
  • 原文地址:https://www.cnblogs.com/lulu638/p/4498849.html
Copyright © 2011-2022 走看看