zoukankan      html  css  js  c++  java
  • 进程 触发器

    1.进程是相当于一个后台运行,赋予一个值,他能给出相关的结果。

      --创建一个过程 "给你一个员工号 你给我返回他的年薪"

        create or replace procedure  nianxin(eno in number, psal out number)        --'nianxin'是进程的名字 eno输入数据  in 代表输入值  number 类型 psal输出数据

        as                                               ---进程之中不用   declare

         csal emp.sal%type;                  

         ccomm emp.comm%type;

        begin

          select sal ,comm into csal,ccomm from emp where empno=eno;

          psal :=sal *12 + nvl( ccomm,0);                --注意 nvl 的作用

        end;

        /

        --------------运用进程

       declare

          psal number;

          begin

          nianxin(7566,psal);               ------psal是返回值, 7566是赋予值

          dbms_output.put_line(psal);

          end;

          /

    ------------- ---------------触发器: 建立一个触发器,当发现定义的操作时,给出 回应

         建立:周四 周天 9:00-18:00 时间段不能 insert 操作

    create or replace trigger empinert   ----------------trigger 关键字

     before                      -----------------before  关键字 (before  ,  after )之前 之后

    insert                         -------------------触发操作

    on emp                         ------------------------基于哪个表

    begin

    if to_char(sysdate,'day') = '星期四' or to_char(sysdate,'day') ='星期天' or to_char(sysdate,'hh24') not between 9 and 18 then raise_application_error(-20003,'不能在非上班时间做插入操作');          -----to_char 将格式转换 只取 一部分

    end if;

    end;

    /

    -------------------监控每个部门不能超过 5 个人

    create or replace trigger empinsert

    before

    insert/delete/update (of) 列名

    on emp

    for each row (when)条件

    declare

          pnumber number;

    begin

         select count(*) into pnumber from emp where deptno = :new.deptno;    -------------:new.deptno   来源于更新后数据下的部门号

         if pnumber >= 5 then raise_application_error(-20002,'每个部门只能有5各员工');

         end if;

    end;

    /

         

  • 相关阅读:
    Entity Framework Core 2.0 新特性
    asp.net core部署时自定义监听端口,提高部署的灵活性
    asp.net core使用jexus部署在linux无法正确 获取远程ip的解决办法
    使用xshell连接服务器,数字键盘无法使用解决办法
    使用Jexus 5.8.2在Centos下部署运行Asp.net core
    【DevOps】DevOps成功的八大炫酷工具
    【Network】Calico, Flannel, Weave and Docker Overlay Network 各种网络模型之间的区别
    【Network】UDP 大包怎么发? MTU怎么设置?
    【Network】高性能 UDP 应该怎么做?
    【Network】golang 容器项目 flannel/UDP相关资料
  • 原文地址:https://www.cnblogs.com/savepoint/p/5316323.html
Copyright © 2011-2022 走看看