zoukankan      html  css  js  c++  java
  • Oracle 函数触发器

    -------------------------------触发器测试----------------------------------------
    ----创建测试表
    CREATE TABLE ZYJ_CS (
    ID INT ,
    NAME NVARCHAR2(20)
    );
    
    --插入测试数据
    INSERT INTO ZYJ_CS(ID,NAME) VALUES (1,'测试');
    INSERT INTO ZYJ_CS(ID,NAME) VALUES (2,'测试2');
    INSERT INTO ZYJ_CS(ID,NAME) VALUES (3,'测试3');
    COMMIT;
    SELECT * FROM ZYJ_CS;
    
    --创建备份表
    CREATE TABLE ZYJ_CS_BK AS SELECT * FROM ZYJ_CS WHERE 1=0;
    SELECT * FROM ZYJ_CS_BK;
    
    
    --创建触发器  
    CREATE OR REPLACE TRIGGER TG_ZYJ_CS_DEL
    BEFORE DELETE ON ZYJ_CS FOR EACH ROW
    BEGIN 
      INSERT INTO ZYJ_CS_BK(ID,NAME)VALUES(:OLD.ID,:OLD.NAME);
    END ;
      
      
    --触发器测试
    SELECT * FROM ZYJ_CS_BK WHERE ID=1;
    DELETE FROM ZYJ_CS WHERE ID=1;
    COMMIT;
    SELECT * FROM ZYJ_CS_BK WHERE ID=1;
    
    --删除表
    DROP TABLE ZYJ_CS;
    DROP TABLE ZYJ_CS_BK;
    
    -------------------------------有参带返回值函数----------------------------------------
    --创建有参函数,返回三数最大值
    CREATE OR REPLACE FUNCTION FN_GETMAX(
      NUM1 IN  NUMBER, 
      NUM2 IN  NUMBER,
      NUM3 IN NUMBER
    ) RETURN NUMBER
    AS
    MAXNUM NUMBER :=0;  
    BEGIN 
     SELECT GREATEST(GREATEST(NUM1,NUM2),NUM3) INTO MAXNUM FROM DUAL;
     RETURN MAXNUM;
    END ;
    
    
    --调用
    SELECT FN_GETMAX(23,45,89) AS 最大值 FROM DUAL;
    

      

  • 相关阅读:
    oracle性能监控
    MySQL Explain详解
    oracle中merge into用法解析
    Mysql常见函数
    Quartz -第一篇-入门
    搭建zookeeper集群
    linux 安装mysql
    mysql无法远程访问
    ActiveMQ 持久化
    Nyoj 城市平乱(图论)
  • 原文地址:https://www.cnblogs.com/soulsjie/p/13173738.html
Copyright © 2011-2022 走看看