首页 > 数据库 >oracle触发器简单使用

oracle触发器简单使用

时间:2022-11-15 13:12:47浏览次数:33  
标签:comment sysdate 触发器 column memo date 简单 oracle public

触发器的作用

数据确认,实施复杂的安全性检查,数据的备份和同步,对于违反规定数据库操作进行监控

 触发器创建语法

 

创建前置触发器,在执行insert操作时,自动修改创建时间和更新时间
create or replace trigger tri_public_memo
before 
   insert
   on public_memo
     for each row
  begin 
    select sysdate into :NEW.created_date from dual;
    select sysdate into :NEW.updated_date from dual;
  end;

  

创建前置触发器,在update操作时,只修改更新时间
create or replace trigger tri_public_memo_up
before 
   update
   on public_memo
     for each row
  begin 
    select sysdate into :NEW.updated_date from dual;
  end;

  

insert into public_memo(ids,title,contents,address,longitude,latitude,status)
values (sys_guid(),'4','23','浦东大道003',12.1234,13.2345,'4');

update public_memo ta set ta.title='5',ta.address='浦东大道004'
where ta.ids='E10A6C4EF00641B6B971627BEC823A2B'

  

 

 

查询public_memo表下的所有触发器
select trigger_name from all_triggers where table_name='PUBLIC_MEMO'; 

  

删除触发器

DROP TRIGGER trigger_name;

建表语句

create table public_memo(
   ids varchar2(32) not null,
   title varchar2(255) not null,
   contents clob not null,
   address varchar(255) not null,
   longitude number(13,10) not null,
   latitude number(13,10) not null,
   created_date date,
   updated_date date,
   status varchar2(4) not null
)
comment on table   public_memo is '备忘录';
  
comment on column public_memo.ids is '主键id';
  
comment on column public_memo.title is '标题';
  
comment on column public_memo.contents is '内容';
  
comment on column public_memo.address is '地址';
  
comment on column public_memo.longitude is '经度';
  
comment on column public_memo.latitudeis '纬度';
  
comment on column public_memo.created_date is '创建时间';
  
comment on column public_memo.updated_date is '修改时间';
  
comment on column public_memo.status is '状态';

insert into public_memo(ids,title,contents,address,longitude,latitude,created_date,updated_date,status)
values (sys_guid(),'1','23','浦东大道',12.1234,13.2345,sysdate,sysdate,'1');
  
insert into public_memo(ids,title,contents,address,longitude,latitude,created_date,updated_date,status)
values (sys_guid(),'2','24','浦东大道001',12.1234,13.2345,sysdate,sysdate,'2');
  
  
insert into public_memo(ids,title,contents,address,longitude,latitude,created_date,updated_date,status)
values (sys_guid(),'3','25','浦东大道002',12.1234,13.2345,sysdate,sysdate,'3');

  

标签:comment,sysdate,触发器,column,memo,date,简单,oracle,public
From: https://www.cnblogs.com/q202105271618/p/16426480.html

相关文章

  • Python取余/求余(%)问题,负数求余最简单的解释
      Python求余中会犯的错误思想如下:    一.忘记求商结果是负数时要向下取整,比如-2.25等于-3。    二.是把负数求余运算和正数求余运算混为一谈  ......
  • Vue3+Vite简单使用
    前言Vue3大势不可阻挡,与之而来的就是Vite,尤雨溪极力推荐的前端开发与构建工具vue3原生支持TS,所以TS语法和vue3TS语法学起来vue中的vuex状态管理也用不顺手,看不顺......
  • 一个简单的网络爬虫教程
    初入爬虫行业的程序员,往往会因为爬虫代码一个字符错误导致程序不能正常运行而且检查起来繁琐,耗费大量的精力,前期学习可以借鉴同行的代码加以完善,后期等技术能力达到一定的标......
  • RabbitMq简单模式
    RabbitMq简单模式定义一个生产者,负责发送消息到队列中/***@authorzjh*生产者发信息*/publicclassProducer{/***队列名称*/public......
  • Pikachu-一些简单的题
    目录遍历漏洞这题直接查找你想要的核心文件,比较简单敏感信息泄露查看网页源代码发现有账号和密码,直接登录PHP反序列化根据概述提示得知classS{public$......
  • Oracle中的substr()函数,截取字符串
    实例、selectsubstr('HelloWorld',0,3)valuefromdual;//返回结果:Hel,截取从“H”开始3个字符、selectsubstr('HelloWorld',1,3)valuefromdual;//返回结果:Hel,截取......
  • PMS简单学习【2.PMS开始安装APK-APK安装】
    PMS简单学习【2.PMS开始安装APK-APK安装】PMS实际对apk的处理的来源还是要从PackageInstallerSession谈起。之前在PackageInstallerSession进行完安装前的准备工作后,最后......
  • 动态代理简单代码
     /***业务接口*/publicinterfaceSubject{voidcall();} /***业务接口的实现(被代理的类)*/publicclassRealSubjcetimplementsSubject{......
  • Loj 6053 简单的函数 min25筛
    #6053.简单的函数先求g(n,j)目的是为了在求S(n,j)的时候可以快速获取一些质数上的点的值。所以我们只要求g(n,j)的质数处的值正确即可其他值则不需要所以我们可以让g......
  • 随机变量指示器的简单应用
    定义设有样本空间\(S\),定义其中一个事件\(A\)的随机变量指示器(indicatorrandomvariable)\(I\{A\}\)为\[I\{A\}:=\begin{cases}1&\text{ifAhappens,}\\0......