我剛剛從SQL Server移動到ORACLE,並且正在處理腳本(SQL Server樣式)。 在SQL Server中,我們在腳本中應用一些邏輯之後使用BEING TRAN-END TRAN。這可以在BEGIN-END塊內完成。 在Oracle中,我發現這有點困難。經過大量的谷歌搜索和搜索這個網站,我仍然不清楚我怎麼能滿足這個要求。可以提交應用於腳本中的每個INSERT INTO?
當我運行腳本(粘貼在下面)時,它作爲一個事務運行。並且一旦整個腳本被執行,DBMS_OUTPUT.Put_line也會顯示。 每次提交後,有沒有辦法打印DBMS_OUTPUT.Put_line?
而且,我打開思路,如果有任何其他的方式來對這個劇本的工作,讓每一個子查詢提交腳本移動到下一個子查詢之前...請讓我知道。
這裏是我的腳本:
SET SERVEROUTPUT ON;
--spool Consolidated.log;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
SET DEFINE OFF;
ALTER SESSION SET GLOBAL_NAMES=FALSE;
DECLARE
ExtractType NUMBER(9);
RecordsExtracted NUMBER(9);
CurStatus NUMBER(9);
StartDate date;
ErrorMessage NVARCHAR2(1000);
LastExtrctTimestamp DATE;
BEGIN
-- AgreementTradeTypes
StartDate := sysdate;
ExtractType := 44;
DELETE FROM AgreementTradeTypes;
INSERT INTO AgreementTradeTypes (AgreementId,AgreementName,PrincipalId,Principal,CounterpartyId,Counterparty, TradeTypeId,TradeTypeName,BusinessLine,AdditionalCriteria)
-- From CORE DB
SELECT
IATT.AgreementId, AG.AgreementName, IATT.PRINCIPALID, Principal.ENTITYNAME Principal,
IATT.COUNTERPARTYID, Cpty.ENTITYNAME Counterparty,
IATT.TradeTypeID, TT.TradeTypeName, BusLine.ENUMTEXT BusinessLine, IATT.ADDITIONALCRITERIA
FROM [email protected] IATT
INNER JOIN [email protected] Principal ON IATT.PRINCIPALID = Principal.ENTITYID
INNER JOIN [email protected] Cpty ON IATT.CounterpartyId = Cpty.ENTITYID
INNER JOIN [email protected] BusLine ON IATT.BusinessLine = BusLine.ENUMVALUE AND BusLine.ENUMTYPE = 'BusinessLine'
INNER JOIN [email protected] AG ON IATT.AGREEMENTID = AG.AgreementID
INNER JOIN [email protected] TT ON IATT.TRADETYPEID = TT.TradeTypeID
ORDER BY IATT.AgreementId;
RecordsExtracted := SQL%RowCount;
DBMS_OUTPUT.put_line('AgreementTradeTypes Records Extracted:' || RecordsExtracted);
-- On Success
CurStatus := 2;
ErrorMessage := 'AgreementTradeTypes Complete';
INSERT INTO ExtractRecords(ExtractType, RecordsExtracted, Status, ExtractTimestamp, StartDate, EndDate, ErrorMessage)
VALUES (ExtractType, RecordsExtracted, CurStatus, SysDate, StartDate, SysDate, ErrorMessage);
INSERT INTO LoadRecords (LoadType,Status,LoadTimestamp,StartDate,EndDate)
VALUES (ExtractType, CurStatus, SysDate, StartDate, SysDate);
COMMIT; /* Committing first Block */
-- INTEREST PAYMENT PERIODS
StartDate := sysdate;
ExtractType := 57;
DELETE FROM InterestPaymentPeriods;
INSERT INTO InterestPaymentPeriods (InterestPaymentPeriodId,AgreementId,AgreementName,CurrencyId,CurrencyName,InstrumentId,InstrumentName,PositionType,CollateralMarginType,PeriodStart,PeriodEnd,NextPeriodEnd,AccruedInterest,OpeningBalance,EndingBalance,MarketIndexId,MarketIndexName,Spread,DayCountConvention,CalculationType,ManagingLocation,BusinessLine)
-- From CORE DB
SELECT
IPP.INTERESTPAYMENTPERIODID, IPP.AGREEMENTID, AG.AGREEMENTNAME, IPP.CURRENCYID, CUR.CODE CurrencyName, IPP.INSTRUMENTID,
Instruments.DESCRIPTION InstrumentName, PosType.ENUMTEXT PositionType, CollMargType.ENUMTEXT CollateralMarginType,
IPP.PERIODSTART, IPP.PERIODEND, IPP.NEXTPERIODEND, IPP.ACCRUEDINTEREST, IPP.OPENINGBALANCE, IPP.ENDINGBALANCE,
IPP.MARKETINDEXID, MI.MARKETINDEXNAME, IPP.SPREAD, DCC.ENUMTEXT DayCountConvention, CalcType.ENUMTEXT CalculationType,
Cty.CITYNAME ManagingLocation, BusLine.ENUMTEXT BusinessLine
FROM
[email protected] IPP
INNER JOIN [email protected] AG ON IPP.AGREEMENTID = AG.AGREEMENTID
LEFT OUTER JOIN [email protected] CUR ON IPP.CURRENCYID = CUR.CURRENCYID
LEFT OUTER JOIN [email protected] Cty ON IPP.MANAGINGLOCATIONID = Cty.CITYID
LEFT OUTER JOIN [email protected] MI ON IPP.MARKETINDEXID = MI.MARKETINDEXID
LEFT OUTER JOIN [email protected] ON IPP.INSTRUMENTID = Instruments.INSTRUMENTID
LEFT OUTER JOIN [email protected] PosType ON IPP.POSITIONTYPE = PosType.ENUMVALUE AND PosType.ENUMTYPE = 'PositionType'
LEFT OUTER JOIN [email protected] CollMargType ON IPP.COLLATERALMARGINTYPE = CollMargType.ENUMVALUE AND CollMargType.ENUMTYPE = 'CollateralMarginType'
LEFT OUTER JOIN [email protected] DCC ON MI.DAYCOUNTCONVENTION = DCC.ENUMVALUE AND DCC.ENUMTYPE = 'DayCountConvention'
LEFT OUTER JOIN [email protected] CalcType ON IPP.CALCULATIONTYPE = CalcType.ENUMVALUE AND CalcType.ENUMTYPE = 'CalculationType'
LEFT OUTER JOIN [email protected] BusLine ON IPP.BUSINESSLINE = BusLine.ENUMVALUE AND BusLine.ENUMTYPE = 'BusinessLine';
RecordsExtracted := SQL%RowCount;
DBMS_OUTPUT.put_line('InterestPaymentPeriods Records Extracted:' || RecordsExtracted);
-- On Success
CurStatus := 2;
ErrorMessage := 'Interest_Payment_Periods Complete';
INSERT INTO ExtractRecords(ExtractType, RecordsExtracted, Status, ExtractTimestamp, StartDate, EndDate, ErrorMessage)
VALUES (ExtractType, RecordsExtracted, CurStatus, SysDate, StartDate, SysDate, ErrorMessage);
INSERT INTO LoadRecords (LoadType,Status,LoadTimestamp,StartDate,EndDate)
VALUES (ExtractType, CurStatus, SysDate, StartDate, SysDate);
COMMIT; /* Committing Second Block */
END;
--spool off;
/
非常感謝您的詳細描述。你清除了很多疑問和問題。你的答覆是拼圖拼圖的正確組成部分,昨天做了很多Google搜索之後,我錯過了。 非常感謝! – Shikha 2013-02-19 03:05:45