oracle当表A1,数据发生update时,将字段time更新为当前时间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle当表A1,数据发生update时,将字段time更新为当前时间相关的知识,希望对你有一定的参考价值。

oracle当表A1,数据发生update时,将字段time更新为当前时间

本来我的想法是建立触发器,不过现在看起来还真不能建立触发器。
因为你要修改的表是A1,time字段也是A1的,也就是说修改time字段也会触发A1表的update。不管是before还是after,都等于update A1一直在重复。
个人认为可以写一个存储过程,然后利用这个存储过程修改A1表,存储过程中其实就是两个update语句,一个是update字段的,这个语句需要传参数,比如你要修改的字段、内容等等。另一个语句就是修改时间的,这个不需要参数,只是固定语句,这样应该就可以了。
参考技术A update woaini set name='王五', sj=sysdate where name='李三';
SJ 是系统时间的字段名
参考技术B 在表A1上建立UPDATE的触发器就解决了

oracle大表空间预分配问题

--//使用oracle大表空间带来的好处就是一个表空间仅仅一个数据文件,维护管理简单,但也带来一些问题,就是预分配问题.
--//缺省oracle有一个后台进程监测SMCO (Space Management Coordinator).看文档每个小时唤醒监测1次.
--//当表空间不足时扩展数据文件.这样可以带来一个好处,比如用户大量导入数据,而数据文件需要扩张时,整个业务要稍微停顿.
--//如果事先数据文件扩展了,就可以减少这方面的停顿.

--//受两个隐含参数的_enable_space_preallocation,_kttext_warning.
--//想象一下如果数据文件1T,增加5%,也就是增加50G,假设写入400m/s,也大概需要50000/400 = 125秒完成.

--//补充知识:

MOS 如下文档详细说明了这个进程的作用:

SMCO (Space Management Coordinator) For Autoextend On Datafiles And How To Disable/Enable (文档 ID 743773.1)

What is the function of SMCO background process

SMCO coordinates the following space management tasks. It performs proactive space allocation and space reclamation. It
dynamically spawns slave processes (Wnnn) to implement the task.

SMCO 协调以下空间管理任务。 它执行主动空间分配和空间回收。游戏代理的动态生成从属进程(Wnnn)来实现任务。

表空间级别的空间预分配 - Tablespace-level space (Extent) pre-allocation.

Pre-allocation here refers to datafile extention, Datafile extension happens when a space request (extent
allocation) operation generally triggered via Insert / loading to a segment does not find contiguous space in the
tablespace, the session will extend the file by the next increment set for the datafile and will continue with the
space request or Extent allocation.

这里的预分配是指数据文件扩展,当通常通过插入/加载到段时触发的空间请求(扩展区分配)操作在表空间中找不到连续空间时会发
生数据文件扩展,会话将按照 increment 设置扩展文件,同时将继续使用空间请求或Extent分配。

For SMCO to autoextend a datafile, the AUTOEXTEND should be set to ON for the datafile. SMCO decides to expand the
tablespace based on history, extension is split evenly across all datafiles in the tablespace which have not reached
their maxsize and are still limited to 10% of the full tablespace size in one hourly SMCO wakeup.

(Full tablespace size = Sum of datafile sizes at any given instance of time.)
要使SMCO自动扩展数据文件,应将的数据文件的AUTOEXTEND设置为ON。 SMCO决定根据历史记录扩展表空间,扩展在表空间中的所有数
据文件中均匀分配,这些数据文件尚未达到其maxsize,并且在每小时SMCO唤醒时,扩展空间限制为完整表空间大小的10%。(完整表
空间大小=任何给定时刻的数据文件大小总和。)

Apart from the above mentioned task, the SMCO process is also responsible for performing the following tasks.

updating block and extents counts in SEG$ for locally managed tablespaces after adding an extent (from unpublished
Bug 12940620)
Securefile lob segment pre-extension.
Securefile lob segment in-memory dispenser space pre-allocation.
Securefile lob segment space reclamation (moving free chunks from uncommitted free space area to committed free space area).
Temporary segment space reclamation.

The main advantage is that sessions need not wait for reactive space allocation/deallocation operations as this is
proactively done, and hence a gain in performance.

How to disable and enable the SMCO background process

The feature provided by the SMCOwww.walajiao.com process is called "Tablespace-level space (Extent) pre-allocation."

It can be turned off by setting "_enable_space_preallocation"=0 as below:
ALTER SYSTEM SET "_ENABLE_SPACE_PREALLOCATION" = 0;

The feature can be turned on again any time by setting "_enable_space_preallocation"=3 which is the default value:
ALTER SYSTEM SET "_ENABLE_SPACE_PREALLOCATION" = 3;

The parameter is dynamic and the scope is ALTER SYSTEM.
NOTE:
Please use the double quotes as indicated to prevent an ORA-911 because of the leading \'_\'

Following is other possible settings:

  • 0 to turn off the tbs pre-extension feature.
  • 1 To enable tablespace extension.
  • 2 To enable segment growth.
  • 4 To enable chunk allocation.

以上摘自 MOS 内容,仅供参考。

1.环境:
SCOTTbook> ver1
PORT_STRING VERSION BANNER


x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SYSbook> hide _enable_space_preallocation
NAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD


_enable_space_preallocation enable space pre-allocation TRUE 3 3 FALSE IMMEDIATE

SYSbook> hide _kttext_warning
NAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD


_kttext_warning tablespace pre-extension warning threshold in percentage TRUE 5 5 FALSE IMMEDIATE

--//还有相关参数_ktslj*:
SYSbook> hide _ktslj
NAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD


_ktslj_segext_max_mb segment pre-extension max size in MB (0: unlimited) TRUE 0 0 FALSE IMMEDIATE
_ktslj_segext_retry segment pre-extension retry TRUE 5 5 FALSE IMMEDIATE
_ktslj_segext_warning segment pre-extension warning threshold in percentage TRUE 10 10 FALSE IMMEDIATE
_ktslj_segext_warning_mb segment pre-extension warning threshold in MB TRUE 0 0 FALSE IMMEDIATE

2.解决方法:
alter system set "_enable_space_preallocation"=0;
--//注意监测表空间的使用定期增加表空间大小.

或者限制增长率:
alter system set "_kttext_warning"=1;

以上是关于oracle当表A1,数据发生update时,将字段time更新为当前时间的主要内容,如果未能解决你的问题,请参考以下文章

当表名是参数时Oracle使用动态sql

当表是我在 Oracle 中的类型时如何显示结果

[Oracle]同义词(synonym)

当表中的任何值被更新时触发函数更新时间戳属性

oracle批量更新的问题

oracle 如何实现对单个表批量更新