oracle触发器的问题
时间:2011-12-01
来源:互联网
各位好,本人oracle新手,现在写了个触发器实现数据导入时候自动传入参数调用存储过程,数据是通过perl采集过来的。现在有一个问题,在启用触发器以后数据不是insert而是update导致数据入库失败,下面是写的触发器,存储过程,perl模块,请高手帮忙分析下是哪个地方的问题,谢谢了。
触发器:
CREATE OR REPLACE TRIGGER TRG_S_PM_EQUIP_CPU
before INSERT ON S_PM_EQUIP_CPU FOR EACH ROW
BEGIN
PRO_S_PM_EQUIP_CPU(:NEW.STARTTIME,:NEW.EQUIPNAME);
END trg_S_PM_EQUIP_CPU;
存储过程:
CREATE OR REPLACE PROCEDURE "STWG"."PRO_S_PM_EQUIP_CPU"(
START_TIME IN date,EQUIP_NAME in varchar2
)
as
cpuused_now NUMBER;
cpuused_last NUMBER;
CPUUSED NUMBER;
BEGIN
select CPUUSED into cpuused_now from S_PM_EQUIP_CPU where STARTTIME=START_TIME and EQUIPNAME=EQUIP_NAME;
select CPUUSED into cpuused_last from S_PM_EQUIP_CPU where STARTTIME=START_TIME-30/1440 and EQUIPNAME=EQUIP_NAME;
CPUUSED:=abs(cpuused_now-cpuused_last)/cpuused_last*100;
insert into ALARM_S_PM_EQUIP_CPU VALUES (START_TIME,START_TIME-30/1440,EQUIP_NAME,CPUUSED) ;
commit;
END PRO_S_PM_EQUIP_CPU;
入库模块:
Tryinsert:
$sth_insert_newobj_to_change->execute||((my $r=$DBI::err)&&(my $str=$DBI::errstr));
if($r)
{
#该数据表中可能已经存在
if( $r!=137) {
my $logmess = "(Message:13060) The data already in DB and will be updated !";
&writelog ( \$logmess, 1, 2 );
#update_pmdata($sub_sql_cols,$sub_sql_value,$sub_sql_where,$sub_tablename,$sub_dbh);
$r=update_pmdata($sub_sql_cols,$sql_cols,$sql_value,$primary_cols,$primary_values,$sub_tablename,$sub_dbh);
#锁表情况
} elsif ( $r==137) {
$sub_locknum++;
#insert操作时,出现严重锁表情况,程序退出
if ( $sub_locknum > $sub_lockmax ) {
my $logmess = "(Error:13068) Critical error in insert the $sub_tablename, the table is locked more than $sub_locknum times !";
&writelog ( \$logmess, 1, 2 );
&exitload;
}
my $logmess = "(Error:13069) Error in insert the $sub_tablename, the table is locked, try again !";
&writelog ( \$logmess, 3, 2 );
$r=0;
goto Tryinsert;
触发器:
CREATE OR REPLACE TRIGGER TRG_S_PM_EQUIP_CPU
before INSERT ON S_PM_EQUIP_CPU FOR EACH ROW
BEGIN
PRO_S_PM_EQUIP_CPU(:NEW.STARTTIME,:NEW.EQUIPNAME);
END trg_S_PM_EQUIP_CPU;
存储过程:
CREATE OR REPLACE PROCEDURE "STWG"."PRO_S_PM_EQUIP_CPU"(
START_TIME IN date,EQUIP_NAME in varchar2
)
as
cpuused_now NUMBER;
cpuused_last NUMBER;
CPUUSED NUMBER;
BEGIN
select CPUUSED into cpuused_now from S_PM_EQUIP_CPU where STARTTIME=START_TIME and EQUIPNAME=EQUIP_NAME;
select CPUUSED into cpuused_last from S_PM_EQUIP_CPU where STARTTIME=START_TIME-30/1440 and EQUIPNAME=EQUIP_NAME;
CPUUSED:=abs(cpuused_now-cpuused_last)/cpuused_last*100;
insert into ALARM_S_PM_EQUIP_CPU VALUES (START_TIME,START_TIME-30/1440,EQUIP_NAME,CPUUSED) ;
commit;
END PRO_S_PM_EQUIP_CPU;
入库模块:
Tryinsert:
$sth_insert_newobj_to_change->execute||((my $r=$DBI::err)&&(my $str=$DBI::errstr));
if($r)
{
#该数据表中可能已经存在
if( $r!=137) {
my $logmess = "(Message:13060) The data already in DB and will be updated !";
&writelog ( \$logmess, 1, 2 );
#update_pmdata($sub_sql_cols,$sub_sql_value,$sub_sql_where,$sub_tablename,$sub_dbh);
$r=update_pmdata($sub_sql_cols,$sql_cols,$sql_value,$primary_cols,$primary_values,$sub_tablename,$sub_dbh);
#锁表情况
} elsif ( $r==137) {
$sub_locknum++;
#insert操作时,出现严重锁表情况,程序退出
if ( $sub_locknum > $sub_lockmax ) {
my $logmess = "(Error:13068) Critical error in insert the $sub_tablename, the table is locked more than $sub_locknum times !";
&writelog ( \$logmess, 1, 2 );
&exitload;
}
my $logmess = "(Error:13069) Error in insert the $sub_tablename, the table is locked, try again !";
&writelog ( \$logmess, 3, 2 );
$r=0;
goto Tryinsert;
作者: guochenfeng 发布时间: 2011-12-01
"触发器以后数据不是insert而是update导致数据入库失败"
那错误是发生在手动更新表数据的时候吗?
错误信息是什么?
那错误是发生在手动更新表数据的时候吗?
错误信息是什么?
作者: LuiseRADL 发布时间: 2011-12-01
SQL code
贴错误信息!
作者: cosio 发布时间: 2011-12-01
>[错误] 脚本行:6-6 ---------------------------------------
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "STWG.PRO_S_PM_EQUIP_CPU", line 13
ORA-06512: at "STWG.TRG_S_PM_EQUIP_CPU", line 2
ORA-04088: error during execution of trigger 'STWG.TRG_S_PM_EQUIP_CPU'
脚本行 6,语句行 1,列 12
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "STWG.PRO_S_PM_EQUIP_CPU", line 13
ORA-06512: at "STWG.TRG_S_PM_EQUIP_CPU", line 2
ORA-04088: error during execution of trigger 'STWG.TRG_S_PM_EQUIP_CPU'
脚本行 6,语句行 1,列 12
作者: guochenfeng 发布时间: 2011-12-01
触发器中不能出现commit语句。
作者: LuiseRADL 发布时间: 2011-12-01
引用 4 楼 luiseradl 的回复:
触发器中不能出现commit语句。
触发器中不能出现commit语句。
+1
作者: xiaobn_cn 发布时间: 2011-12-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28