hello Oracle gurus,
It's been quite awhile since I have worked with Oracle.
Today, I have been asked to modify an existing code but I am stumped as to how to proceed.
Per code below, The changes that I am asked to make says that there is a parameter called new_fresh.
If new_fresh = 'R' ( R for Refresh and N for New) then
delete all records from ALTIDINDX
WHERE Taxyr = Param Taxyr and idname = 'RPID'
elseif new_fresh = 'N' then
just execute entire code without deleting anything.
Since this code is not a stored procedure, I can't use an IF statement and I have a hard time with either decode or case statement.
I was wondering if anyone would be kind enough to assist.
Thanks in advance
Here is the code I am trying to modify to add the case or decode statements.
It's been quite awhile since I have worked with Oracle.
Today, I have been asked to modify an existing code but I am stumped as to how to proceed.
Per code below, The changes that I am asked to make says that there is a parameter called new_fresh.
If new_fresh = 'R' ( R for Refresh and N for New) then
delete all records from ALTIDINDX
WHERE Taxyr = Param Taxyr and idname = 'RPID'
elseif new_fresh = 'N' then
just execute entire code without deleting anything.
Since this code is not a stored procedure, I can't use an IF statement and I have a hard time with either decode or case statement.
I was wondering if anyone would be kind enough to assist.
Thanks in advance
Here is the code I am trying to modify to add the case or decode statements.
Code:
SET TRIMSPOOL ON
SET VERIFY OFF
SET SERVEROUTPUT ON SIZE 1000000
col prtque new_value filename
col tyr new_value taxyr
col id1 new_value pid1
col id2 new_value pid2
col param1 new_value rolltypes
col param2 new_value new_refresh
select prtque,
jur,
taxyr tyr,
id1,
id2,
multiparam( 'IN', null, param1 ) param1,
NVL( param2, 'N' ) param2
from param
where rptname='PP504GA';
spool &&filename
DECLARE
CURSOR c IS
SELECT a.jur, a.taxyr, a.parid
FROM ppadmn a
WHERE ( ( '&&pid1' <> 'IDLIST' and a.parid between '&&pid1' and '&&pid2' ) or
( '&&pid1' = 'IDLIST' and a.parid in ( select parid from idlist where setname = '&&pid2' ) ) )
AND a.taxyr = &&taxyr
AND a.rolltype in ( &&rolltypes )
AND ( ( '&&new_refresh' = 'R' ) or
( '&&new_ ' = 'N' and not exists ( select 'x'
from altidindx
where parid = a.parid
and taxyr = a.taxyr
and idname='RPID' ) )
)
AND a.cur = 'Y';
l_count NUMBER := 0;
l_adrno ADDRINDX.ADRNO%TYPE;
l_adrstr ADDRINDX.ADRSTR%TYPE;
l_cityname ADDRINDX.CITYNAME%TYPE;
l_taxyr ADDRINDX.TAXYR%TYPE;
l_loc2 ADDRINDX.LOC2%TYPE;
l_parid PARDAT.PARID%TYPE;
v_cnt NUMBER := 0;
l_upd NUMBER := 0;
l_continue VARCHAR2(1) := 'Y';
l_dashparid VARCHAR2(50);
v_sqlerrm VARCHAR2(4000);
BEGIN
FOR r IN c
LOOP
l_continue := 'Y';
BEGIN
SELECT adrno, adrstr, cityname, taxyr, loc2, dashx(parid)
INTO l_adrno, l_adrstr, l_cityname, l_taxyr, l_loc2, l_dashparid
FROM addrindx
WHERE parid = r.parid
AND taxyr = r.taxyr
AND jur = '000'
AND cur = 'Y';
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'No Address record for this account with parid=' || r.parid || ' and taxyr=' || r.taxyr );
l_continue := 'N';
END;
IF ( l_continue = 'Y' ) THEN
IF (l_adrno is not null AND l_adrstr is not null)
THEN
BEGIN
SELECT PARID
INTO l_parid
FROM PARDAT
WHERE cityname = l_cityname
AND adrstr = l_adrstr
AND adrno = l_adrno
AND taxyr = l_taxyr
AND cur = 'Y';
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'No current PARDAT record for parid=' || l_dashparid || ' and taxyr=' || r.taxyr );
l_parid := null;
END;
end if;
ELSIF (l_adrno is null AND l_adrstr is null AND l_loc2 is not null)
--l_continue := 'Y';
THEN
BEGIN
SELECT PARID
INTO l_parid
FROM PARDAT
WHERE loc2 = l_loc2
AND taxyr = l_taxyr
AND cur = 'Y';
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'No current PARDAT record for parid=' || l_dashparid || ' and taxyr=' || r.taxyr );
l_parid := null;
END;
END IF;
BEGIN
UPDATE ppadmn
SET realref = l_parid
WHERE taxyr = l_taxyr
AND parid = r.parid
AND cur = 'Y';
l_upd := l_upd + SQL%ROWCOUNT;
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'No record exist for update...');
END;
BEGIN
INSERT INTO ALTIDINDX(JUR, PARID, TAXYR, IDNAME, ALTID, WHO, WEN)
VALUES (r.jur, r.parid, r.taxyr, 'RPID', l_parid, 'CONVERT', sysdate);
v_cnt := v_cnt + 1;
EXCEPTION
WHEN dup_val_on_index THEN
UPDATE altidindx
SET altid = l_parid
WHERE jur = r.jur
AND parid = r.parid
AND taxyr = r.taxyr
AND idname = 'RPID';
v_cnt := v_cnt + sql%rowcount;
WHEN others THEN
v_sqlerrm := substr(sqlerrm,1,4000);
dbms_output.put_line(r.jur||'-'||r.parid||'-'||r.taxyr||v_sqlerrm);
END;
END LOOP;
COMMIT;
IF ( l_upd > 0 or v_cnt > 0 ) THEN
dbms_output.put_line( 'Number of PPADMN records updated : ' || l_upd );
dbms_output.put_line( 'Number of ALTIDINDX records created/updated: ' || v_cnt );
ELSE
dbms_output.put_line( 'No records were processed.' );
END IF;
END;
/
spool off