I am migrating a few stored procedures from Sybase to Oracle using Oracle Developer tool. The tool migrates alomost 70%-80% of the stored procedures except a few cases where there is a temporary table created and used inside a stored procedures.
Here is an example:
Existing sybase stored procedure:
CREATE GLOBAL TEMPORARY TABLE tt_RptRCRsn
(
BatchNo CHAR(12) ,
RecNo NUMBER ,
CONTRACT CHAR(9) ,
DateNotified CHAR(10) ,
Reason CHAR(20) ,
LOGIN CHAR(7) ,
CheckNo CHAR(20) ,
Amount NUMBER(10,2) ,
Resolution CHAR(20) ,
ResolvedDt CHAR(10) ,
Comment_ VARCHAR2(100) ,
CW CHAR(1)
);
/
CREATE OR REPLACE PROCEDURE RptRCByRsn
(
v_BegDT IN DATE DEFAULT NULL ,
v_EndDt IN DATE DEFAULT NULL ,
v_C IN CHAR DEFAULT NULL ,
v_W IN CHAR DEFAULT NULL ,
v_Res IN CHAR DEFAULT NULL ,
v_A IN CHAR DEFAULT NULL ,
v_I IN CHAR DEFAULT NULL ,
v_E IN CHAR DEFAULT NULL ,
v_B IN CHAR DEFAULT NULL ,
v_U IN CHAR DEFAULT NULL ,
v_M IN CHAR DEFAULT NULL ,
v_N IN CHAR DEFAULT NULL ,
cv_1 OUT SYS_REFCURSOR
)
AS
BEGIN
IF v_Res = 'Y' THEN
-- Grab all resolved returned checks
INSERT INTO tt_RptRCRsn
( SELECT cw.BatchNo ,
cw.RecNo ,
cw.CONTRACT ,
UTILS.CONVERT_TO_CHAR(NotifyDt,10,p_style=>101) ,
rcr.Reason ,
rc.LOGIN ,
cw.CheckNo ,
cw.Amount ,
rcres.Resolution ,
UTILS.CONVERT_TO_CHAR(rc.ResolvedDt,10,p_style=>101) ,
' ' ,
bs.SourceCode
FROM ReturnChk rc,
ChecksWires cw,
BatchSummary bs,
RCReason rcr,
RCResolution rcres
WHERE RCStatusCd = 'R'
AND rc.BatchNo = cw.BatchNo
AND rc.RecNo = cw.RecNo
AND rc.ReasonCd = rcr.ReasonCd
AND rc.ResCd = rcres.ResCd
AND rc.NotifyDt >= v_BegDt
AND rc.NotifyDt <= v_EndDt
AND bs.SourceCode IN ( v_C,v_W )
AND cw.TransCode IN ( v_A,v_I,v_E,v_B,v_U,v_M,v_N )
AND cw.BatchNo = bs.BatchNo );
ELSE
INSERT INTO tt_RptRCRsn
( SELECT cw.BatchNo ,
cw.RecNo ,
cw.CONTRACT ,
UTILS.CONVERT_TO_CHAR(NotifyDt,10,p_style=>101) ,
rcr.Reason ,
rc.LOGIN ,
cw.CheckNo ,
cw.Amount ,
rcres.Resolution ,
CASE
WHEN rc.ResolvedDt = '01/01/1900' THEN ' '
ELSE UTILS.CONVERT_TO_CHAR(rc.ResolvedDt,10,p_style=>101)
END col ,
' ' ,
bs.SourceCode
FROM ReturnChk rc,
ChecksWires cw,
BatchSummary bs,
RCReason rcr,
RCResolution rcres
WHERE RCStatusCd <> 'R'
AND rc.BatchNo = cw.BatchNo
AND rc.RecNo = cw.RecNo
AND rc.ReasonCd = rcr.ReasonCd
AND rc.ResCd = rcres.ResCd
AND rc.NotifyDt >= v_BegDt
AND rc.NotifyDt <= v_EndDt
AND bs.SourceCode IN ( v_C,v_W )
AND cw.TransCode IN ( v_A,v_I,v_E,v_B,v_U,v_M,v_N )
AND cw.BatchNo = bs.BatchNo );
END IF;
--Get most recent Returned Check comment
UPDATE tt_RptRCRsn
SET Comment_ = ( SELECT COMMENTS.Comment_
FROM Comments
WHERE COMMENTS.BatchNo = tt_RptRCRsn.BatchNo
AND COMMENTS.RecNo = tt_RptRCRsn.RecNo
AND COMMENTS.ComCode = 'R'
AND COMMENTS.ComNo = ( SELECT MAX(COMMENTS.ComNo)
FROM Comments
WHERE COMMENTS.BatchNo = tt_RptRCRsn.BatchNo
AND COMMENTS.RecNo = tt_RptRCRsn.RecNo
AND COMMENTS.ComCode = 'R' ) );
OPEN cv_1 FOR
SELECT BatchNo ,
RecNo ,
CONTRACT ,
DateNotified ,
Reason ,
LOGIN ,
CheckNo ,
Amount ,
Resolution ,
ResolvedDt ,
COMMENT_ ,
CW
FROM tt_RptRCRsn ;
END;
Migrated oracle stored procedure:
/*Global Temporary Tables:1 *//* Translation Extracted DDL For Required Objects*/
CREATE GLOBAL TEMPORARY TABLE tt_RptRCRsn
(
BatchNo CHAR(12) ,
RecNo NUMBER ,
CONTRACT CHAR(9) ,
DateNotified CHAR(10) ,
Reason CHAR(20) ,
LOGIN CHAR(7) ,
CheckNo CHAR(20) ,
Amount NUMBER(10,2) ,
Resolution CHAR(20) ,
ResolvedDt CHAR(10) ,
Comment_ VARCHAR2(100) ,
CW CHAR(1)
);
/
CREATE OR REPLACE PROCEDURE RptRCByRsn
(
v_BegDT IN DATE DEFAULT NULL ,
v_EndDt IN DATE DEFAULT NULL ,
v_C IN CHAR DEFAULT NULL ,
v_W IN CHAR DEFAULT NULL ,
v_Res IN CHAR DEFAULT NULL ,
v_A IN CHAR DEFAULT NULL ,
v_I IN CHAR DEFAULT NULL ,
v_E IN CHAR DEFAULT NULL ,
v_B IN CHAR DEFAULT NULL ,
v_U IN CHAR DEFAULT NULL ,
v_M IN CHAR DEFAULT NULL ,
v_N IN CHAR DEFAULT NULL ,
cv_1 OUT SYS_REFCURSOR
)
AS
BEGIN
/*
12/22/03 MRJ This SP is used to select the data for theReturned Checks by Reason Report.
04/12/06 MRJ ASE 15 Upgrade - Changed @BeginDt and @EndDt from char(10) to smalldatetime.
05/02/08 SHA Updated to identify NAV business in reporting.
*/
IF v_Res = 'Y' THEN
-- Grab all resolved returned checks
INSERT INTO tt_RptRCRsn
( SELECT cw.BatchNo ,
cw.RecNo ,
cw.CONTRACT ,
UTILS.CONVERT_TO_CHAR(NotifyDt,10,p_style=>101) ,
rcr.Reason ,
rc.LOGIN ,
cw.CheckNo ,
cw.Amount ,
rcres.Resolution ,
UTILS.CONVERT_TO_CHAR(rc.ResolvedDt,10,p_style=>101) ,
' ' ,
bs.SourceCode
FROM ReturnChk rc,
ChecksWires cw,
BatchSummary bs,
RCReason rcr,
RCResolution rcres
WHERE RCStatusCd = 'R'
AND rc.BatchNo = cw.BatchNo
AND rc.RecNo = cw.RecNo
AND rc.ReasonCd = rcr.ReasonCd
AND rc.ResCd = rcres.ResCd
AND rc.NotifyDt >= v_BegDt
AND rc.NotifyDt <= v_EndDt
AND bs.SourceCode IN ( v_C,v_W )
AND cw.TransCode IN ( v_A,v_I,v_E,v_B,v_U,v_M,v_N )
AND cw.BatchNo = bs.BatchNo );
ELSE-- Grab all unresolved returned checks
INSERT INTO tt_RptRCRsn
( SELECT cw.BatchNo ,
cw.RecNo ,
cw.CONTRACT ,
UTILS.CONVERT_TO_CHAR(NotifyDt,10,p_style=>101) ,
rcr.Reason ,
rc.LOGIN ,
cw.CheckNo ,
cw.Amount ,
rcres.Resolution ,
CASE
WHEN rc.ResolvedDt = '01/01/1900' THEN ' '
ELSE UTILS.CONVERT_TO_CHAR(rc.ResolvedDt,10,p_style=>101)
END col ,
' ' ,
bs.SourceCode
FROM ReturnChk rc,
ChecksWires cw,
BatchSummary bs,
RCReason rcr,
RCResolution rcres
WHERE RCStatusCd <> 'R'
AND rc.BatchNo = cw.BatchNo
AND rc.RecNo = cw.RecNo
AND rc.ReasonCd = rcr.ReasonCd
AND rc.ResCd = rcres.ResCd
AND rc.NotifyDt >= v_BegDt
AND rc.NotifyDt <= v_EndDt
AND bs.SourceCode IN ( v_C,v_W )
AND cw.TransCode IN ( v_A,v_I,v_E,v_B,v_U,v_M,v_N )
AND cw.BatchNo = bs.BatchNo );
END IF;
--Get most recent Returned Check comment
UPDATE tt_RptRCRsn
SET Comment_ = ( SELECT COMMENTS.Comment_
FROM Comments
WHERE COMMENTS.BatchNo = tt_RptRCRsn.BatchNo
AND COMMENTS.RecNo = tt_RptRCRsn.RecNo
AND COMMENTS.ComCode = 'R'
AND COMMENTS.ComNo = ( SELECT MAX(COMMENTS.ComNo)
FROM Comments
WHERE COMMENTS.BatchNo = tt_RptRCRsn.BatchNo
AND COMMENTS.RecNo = tt_RptRCRsn.RecNo
AND COMMENTS.ComCode = 'R' ) );
OPEN cv_1 FOR
SELECT BatchNo ,
RecNo ,
CONTRACT ,
DateNotified ,
Reason ,
LOGIN ,
CheckNo ,
Amount ,
Resolution ,
ResolvedDt ,
Comment_ ,
CW
FROM tt_RptRCRsn ;
END;
The migrated stored procedure compiles with an error - 'Table or view does not exist' even though global temporary table was created. The migrated proceure is not able to find the global temporary table 'tt_RptRCRsn'.
I tried giving grant all to this stored procedure but still its not compiling,
I dont want to make major modifications to the stored procedure as this is the requirement to keep the migrated code (oracle procedures) as similar as possible to the existing code (Sybase procedures)
Can someone please suggest a solution on how do I achieve this?