|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于insert和delete,event中包含了插入/删除的记录的所有字段的值(太爽了。。)非常处置
这是Pona的文章,我大胆将其贴下去,Pona不要介怀哦!^_^
PL/SQL里,有三种办法能够在处置多量量数据时不会由于一条或几条数据毛病而招致非常中断程序。
1、用Fetchintoacursor%TYPE把要处置的数据放到纪录集里。当一条数据不符前提时,用标签<<NEXT_RECORD>>和GOTONEXT_RECORD跳转语句使程序疏忽这一条,转到下一条持续处置。
-------------------------------------------------------------------------------
--FunctionName:CalculateImportCharge
--FunctionDesc:CalculateImportCharge
--Createdby:Author
--CreatedDate:2003-05-16
-------------------------------------------------------------------------------
FUNCTIONCalculateImportCharge(
p_i_job_idINVARCHAR2,
p_i_as_of_date_idINVARCHAR2)RETURNNUMBER
AS
CURSORcur_ShipBlHeaderIS
SELECTimport_folder_no
FROMGMY_SHIP_BL_HEADER
WHERECANCEL_FLG=GMY_GA000_PKG.BL_CANCEL_FLG_OFF;
rec_ShipBlHeadercur_ShipBlHeader%ROWTYPE;
BEGIN
OPENcur_ShipBlHeader;
FETCHcur_ShipBlHeaderINTOrec_ShipBlHeader;
WHILEcur_ShipBlHeader%FOUNDLOOP
x_num_error_code:=GMY_GA000_PKG.CheckValidMasterBlNo(
p_i_job_id,
p_i_as_of_date_id,
rec_ShipBlHeader.import_folder_no,
x_vch_message);
IFx_num_error_code
IN(GMY_GA000_PKG.gn#NG,GMY_GA000_PKG.INVALID_BL_NO)THEN
x_vch_message:=
p_i_job_id
||WARNING:FunctionCheckValidMasterBlNo@
||Importfolder
||rec_ShipBlHeader.import_folder_no
||-InvalidBLNo.;
COM_LOG.PUTLINE(p_i_job_id,x_vch_message);
GOTONEXT_RECORD;
ENDIF;
x_num_error_code:=CheckExistsOfAccDate(
p_i_job_id,
p_i_as_of_date_id,
rec_ShipBlHeader.import_folder_no);
IFx_num_error_code=GMY_GA000_PKG.gn#NGTHEN
GOTONEXT_RECORD;
ENDIF;
COMMIT;
<<NEXT_RECORD>>
FETCHcur_ShipBlHeaderINTOrec_ShipBlHeader;
ENDLOOP;
CLOSEcur_ShipBlHeader;
RETURNGMY_GA000_PKG.gn#OK;
EXCEPTION
WHENOTHERSTHEN
x_vch_message:=
p_i_job_id
||ERROR:FunctionCalculateImportCharge@
||SUBSTR(SQLERRM(SQLCODE),1,100);
COM_LOG.PUTLINE(p_i_job_id,x_vch_message);
RETURNGMY_GA000_PKG.gn#NG;
ENDCalculateImportCharge;
2、当利用theCursorFORLoop轮回时,在Loop轮回里,把会出成绩的情形写进一个自力的block块中,这个块包含完全的begin、end部分及exception非常处置部分。如许即便一条数据呈现非常,也会持续实行下一条。
-------------------------------------------------------------------------------
--FunctionName:GenerateInsCostInfRec
--FunctionDesc:GeneraterecordstotransmitinINFtable
--Createdby:SISS(AP)
--CreatedDate:2003-03-26
------------------------------------------------------------------------------
FUNCTIONGenerateInsCostInfRec(
p_i_job_idINVARCHAR2,
p_i_as_of_date_idINVARCHAR2)RETURNNUMBER
AS
CURSORcur_costIS
SELECTcost.ROWIDcostRowId,
cost.import_folder_no,,
cost.insur_trans_id
FROMGMY_COST_BLcost,
GMY_COMMON_MSTmst
WHEREcost.import_folder_no=invheader.import_folder_no
ANDcost.billing_amt_numISNOTNULL
ANDcost.billing_amt_num!=0
ANDcost.insur_db_cr!=0;
BEGIN
FORrec_costINcur_costLOOP
BEGIN
x_num_ret_value:=GMY_GA000_PKG.CheckValidMasterBlNo(
p_i_job_id,
p_i_as_of_date_id,
rec_cost.import_folder_no,
x_vch_error_msg);
IFx_num_ret_value=GMY_GA000_PKG.VALID_BL_NOTHEN
INSERTINTOGMY_COST_INS_INF(
cost_trx_id,,
created_by,
program_name)
VALUES(
GMY_COST_INS_INF_S.NEXTVAL,
PRG_NAME,
PRG_NAME);
ELSIFx_num_ret_value=GMY_GA000_PKG.INVALID_BL_NOTHEN
x_vch_error_msg:=p_i_job_id
||Importfolder
||rec_cost.import_folder_no
||hasrepeatedBLNo.withotherimportfolder.
||Failedininsurancecosttransmission.;
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
ENDIF;
EXCEPTION
WHENOTHERSTHEN
IFSQL%ROWCOUNT>0THEN--checkfortoomanyrows
x_vch_error_msg:=p_i_job_id||||
SUBSTR(SQLERRM(SQLCODE),1,100);
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
ELSE
x_vch_error_msg:=p_i_job_id||||
SUBSTR(SQLERRM(SQLCODE),1,100);
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
ENDIF;
END;
ENDLOOP;
COMMIT;
RETURNGMY_GA000_PKG.gn#OK;
EXCEPTION
WHENOTHERSTHEN
x_vch_error_msg:=p_i_job_id||||SUBSTR(SQLERRM(SQLCODE),1,100);
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
ROLLBACK;
RETURNGMY_GA000_PKG.gn#NG;
ENDGenerateInsCostInfRec;
3、当利用theCursorFORLoop轮回时,在Loop轮回里,把会出成绩的情形拆分红子函数,分离处置。
----------------------------------------------------------------------------
--FunctionName:CopyDsToActualDs
--FunctionDesc:CopytherecordsfromDSDBtoActualDSDB.
--Createdby:Author
--CreatedDate:2003-02-20
----------------------------------------------------------------------------
FUNCTIONCopyDsToActualDs(
p_i_job_idINVARCHAR2,
p_i_as_of_date_idINVARCHAR2)RETURNNUMBER
IS
CURSORcur_DsSccIS
SELECT*
FROMGMY_DS_SCC;
BEGIN
FORrec_DsHeadINcur_DsSccLOOP
x_num_error_code:=InsToActualScc(
p_i_job_id,
p_i_as_of_date_id,
rec_DsHead.order_by_code,
rec_DsHead.po_code,
rec_DsHead.wh);
ENDLOOP;
EXCEPTION
WHENOTHERSTHEN
x_vch_error_msg:=p_i_job_id
||FunctionName:CopyDsToActualDs;
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
x_vch_error_msg:=p_i_job_id||||SUBSTR(SQLERRM(SQLCODE),1,100);
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
ROLLBACK;
RETURNGMY_GA000_PKG.gn#NG;
ENDCopyDsToActualDs;
----------------------------------------------------------------------------
--FunctionName:InsToActualScc
--FunctionDesc:Dealwithinsertsection.
--Createdby:Author
--CreatedDate:2003-03-13
----------------------------------------------------------------------------
FUNCTIONInsToActualScc(
p_i_job_idINVARCHAR2,
p_i_as_of_date_idINVARCHAR2,
p_i_order_by_codeINVARCHAR2,
p_i_po_codeINVARCHAR2,
p_i_whINVARCHAR2
)RETURNNUMBER
IS
x_vch_error_msgVARCHAR2(255);
BEGIN
INSERTINTOGMY_ACTUAL_DS_SCC(
order_by_code,
po_code,
wh)
VALUES(p_i_order_by_code,
p_i_po_code,
p_i_wh);
COMMIT;
RETURNGMY_GA000_PKG.gn#OK;
EXCEPTION
WHENOTHERSTHEN
x_vch_error_msg:=p_i_job_id||FunctionName:InsToActualScc;
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
x_vch_error_msg:=p_i_job_id
||Thekeyoftherecordthatfailedtoinsertis:;
COM_LOG.PUTLINE(p_i_job_id,x_vch_error_msg);
ROLLBACK;
RETURNGMY_GA000_PKG.gn#NG;
ENDInsToActualScc;
InnoDB事务型数据库的首选引擎,支持ACID事务,支持行级锁定 |
|