I have a script that execute the following stored procedure:
Create or Replace Procedure Incxxx.spFCTVersion(
IN_YR IN Varchar2,
IN_Ver IN Varcahr2,
IN_Month IN Varchar2,
IN_Dest_Ver IN Varchar2,
IN_Dest_Month IN VarChar2)
AS
Begin
DECLARE
IN_Year NUMBER(8) :=To_Number(IN_YR);
IN_Year_ID NUMBER(8);
IN_VerID NUMBER(8);
IN_Dest_VerID NUMBER(8);
v_unitid tbl_base.unit_id%TYPE;
v_yearid tbl_base.year_id%TYPE;
v_lineid tbl_base.line_id%TYPE;
v_verid tbl_base.ver_id%TYPE;
v_jan tbl_base.jan%TYPE;
v_feb tbl_base.feb%TYPE;
v_mar tbl_base.mar%TYPE;
v_apr tbl_base.apr%TYPE;
v_may tbl_base.may%TYPE;
v_jun tbl_base.jun%TYPE;
v_jul tbl_base.jul%TYPE;
v_aug tbl_base.aug%TYPE;
v_sep tbl_base.sep%TYPE;
v_oct tbl_base.oct%TYPE;
v_nov tbl_base.nov%TYPE;
v_dec tbl_base.dec%TYPE;
--********* Get all the version ids from ver table ***************
Select mem_ID
into IN_Year_ID
from Incxxx.year
where mem_name = IN_Year;
Select mem_ID
into IN_VerID
from Incxxx.ver
where upper(mem_name) = IN_Ver';
Select mem_id
into IN_Dest_VerID
from Incxxx.ver
where upper(mem_name) = IN_Dest_Ver;
--retrieve source Period from source version
CURSOR c_Ver IS
SELECT unit_id, year_id, line_id, ver_id, IN_Month
FROM Incxxx.tbl
WHERE ver_id = IN_VerID;
BEGIN
OPEN c_Ver
LOOP
FETCH c_Ver INTO v_unitid, v_yearid, v_lineid, v_verid, v_|| IN_Month ||
EXIT WHEN c_Ver%NOTFOUND;
Update Incxxx.tbl_base
set || IN_Dest_Month || = v_ || IN_Month ||
where year_id = v_yearid and unit_id = v_unitid and ver_id=IN_Dest_VerID and line_id=v_lineid;
IF SQL%NOTFOUND THEN
Insert into Incxxx.tbl_base
(year_id,line_id,unit_id,ver_id,PO,_|| IN_Dest_Month ||)
values(v_yearid,v_lineid,v_unitid, IN_Dest_VerID,null,v_|| IN_Month ||);
END IF;
END LOOP;
--Free resources used by cursor
CLOSE c_Ver
--Commit update
COMMIt
Can somebody tell me if I did the substitution variable correctly.
Create or Replace Procedure Incxxx.spFCTVersion(
IN_YR IN Varchar2,
IN_Ver IN Varcahr2,
IN_Month IN Varchar2,
IN_Dest_Ver IN Varchar2,
IN_Dest_Month IN VarChar2)
AS
Begin
DECLARE
IN_Year NUMBER(8) :=To_Number(IN_YR);
IN_Year_ID NUMBER(8);
IN_VerID NUMBER(8);
IN_Dest_VerID NUMBER(8);
v_unitid tbl_base.unit_id%TYPE;
v_yearid tbl_base.year_id%TYPE;
v_lineid tbl_base.line_id%TYPE;
v_verid tbl_base.ver_id%TYPE;
v_jan tbl_base.jan%TYPE;
v_feb tbl_base.feb%TYPE;
v_mar tbl_base.mar%TYPE;
v_apr tbl_base.apr%TYPE;
v_may tbl_base.may%TYPE;
v_jun tbl_base.jun%TYPE;
v_jul tbl_base.jul%TYPE;
v_aug tbl_base.aug%TYPE;
v_sep tbl_base.sep%TYPE;
v_oct tbl_base.oct%TYPE;
v_nov tbl_base.nov%TYPE;
v_dec tbl_base.dec%TYPE;
--********* Get all the version ids from ver table ***************
Select mem_ID
into IN_Year_ID
from Incxxx.year
where mem_name = IN_Year;
Select mem_ID
into IN_VerID
from Incxxx.ver
where upper(mem_name) = IN_Ver';
Select mem_id
into IN_Dest_VerID
from Incxxx.ver
where upper(mem_name) = IN_Dest_Ver;
--retrieve source Period from source version
CURSOR c_Ver IS
SELECT unit_id, year_id, line_id, ver_id, IN_Month
FROM Incxxx.tbl
WHERE ver_id = IN_VerID;
BEGIN
OPEN c_Ver
LOOP
FETCH c_Ver INTO v_unitid, v_yearid, v_lineid, v_verid, v_|| IN_Month ||
EXIT WHEN c_Ver%NOTFOUND;
Update Incxxx.tbl_base
set || IN_Dest_Month || = v_ || IN_Month ||
where year_id = v_yearid and unit_id = v_unitid and ver_id=IN_Dest_VerID and line_id=v_lineid;
IF SQL%NOTFOUND THEN
Insert into Incxxx.tbl_base
(year_id,line_id,unit_id,ver_id,PO,_|| IN_Dest_Month ||)
values(v_yearid,v_lineid,v_unitid, IN_Dest_VerID,null,v_|| IN_Month ||);
END IF;
END LOOP;
--Free resources used by cursor
CLOSE c_Ver
--Commit update
COMMIt
Can somebody tell me if I did the substitution variable correctly.