Oracle存储过程使用游标的技巧代码(2)
CLOSE myCusor;
END;
--选择最近芯片状态变更时间
--SELECT MIN(F_CURRENTTIME)INTO v_NOW FROM T_CHIPSTATEHISTORY WHERE F_HISTORYSTATE = 20
AND F_CHIPID IN (SELECT F_ID FROM T_CHIP WHERE F_InlayBoxID=(SELECT F_ID FROM T_InlayBox
WHERE F_InlayOutID=FID));
--将芯片表中芯片状态更新到以前状态
--UPDATE T_CHIP SET F_State=20,F_CompareTime=v_NOW WHERE F_InlayBoxID IN (SELECT F_ID FROM
T_InlayBox WHERE F_InlayOutID =FID);
--记录芯片状态变更日志
--INSERT INTO T_ChipStateHistory (F_ChipID,f_Historystate,f_Tableid,f_Currenttime,f_Tablename)VALUES
--((SELECT F_ID FROM T_CHIP WHERE F_InlayBoxID=(SELECT F_ID FROM T_InlayBox WHERE F_InlayOutID=FID)),
20,v_LogID,SYSDATE,'T_InlayOut_Log');
--将Inlay出库箱表中以前的数据更新到以前状态
UPDATE T_InlayBox SET F_State=2,F_InlayOutID=null WHERE F_InlayOutID =FID;
--编辑时将新的INLAY出库信息更新
UPDATE T_InlayOut SET F_InlayBoxIDs=InlayBoxIDs,f_Boxcount=BoxCount,f_Applyuserid=ApplyUserID,
f_Storeuserid=StoreUserID,f_Confirmstate=ConfirmState,F_ExistState=ExistState,F_ConfirmTime=null
WHERE F_ID=FID;
--更新T_InlayBox 新的状态
--UPDATE T_InlayBox SET F_State=3,F_InlayOutID=FID WHERE F_ID in (InlayBoxIDs);
v_sql := 'UPDATE T_InlayBox SET F_State=3,F_InlayOutID='||FID||' WHERE F_ID in ('||InlayBoxIDs||')';
--立即执行v_sql
EXECUTE IMMEDIATE v_sql;
SELECT SYSDATE INTO v_Now2 FROM DUAL;
--更新芯片表状态
UPDATE T_Chip SET F_State='No_Confirm_InlayOut',F_CompareTime=v_Now2 WHERE F_InlayBoxID IN
(SELECT F_ID FROM T_InlayBox WHERE F_InlayOutID=FID);
--记录当前操作日志
INSERT INTO T_ChipStateHistory (F_ChipID,f_Historystate,f_Tableid,f_Currenttime,f_Tablename)
SELECT F_ID,'No_Confirm_InlayOut',v_LogID,v_Now2,'T_InlayOut_Log' FROM T_CHIP WHERE F_InlayBoxID IN
(SELECT F_ID FROM T_InlayBox WHERE F_InlayOutID=FID);
--提交
COMMIT;
--发生异常时返回错误码
EXCEPTION
WHEN OTHERS THEN
strErr := substr(sqlerrm,1,100);
ROLLBACK;
END sp_EditInlayOut;
但是在SQLSERVER中,除非你将所有的T-SQL语句块以显示的方式【BEGIN TRANSACTION …END TRANSACTION】申明在事务中,否则SQLSERVER会将语句块中的每一句作为一个单独的默认事务执行。
相关新闻>>
- 发表评论
-
- 最新评论 更多>>