Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

prematurely ending script

613809Dec 16 2007 — edited Dec 18 2007
Hi,

I am writing a script to update a residence column in a table containing client details. There are a number of incorrectly spelled street names in the column which occurred during data entry which need to be replaced with the correct street name (incorrect and correct street name combinations are stored in a seperate table). For some reason the script prematurely completes (successfully so toad tells me) when the following type of street name replacement occurs

Incorrect street name: Chimney
Correct street name: Chimney Heights

I think that it may be occurring when the records are being selected from the tables but have i'm not too sure. The script will stop after inserting records of this type, if I delete the particular record then my script will continue until another instance of this type of record is selected/inserted.

Does anyone know why this would be happening or how I can get around it? The script is below.

declare

owner_id owners.IDENT%type;
owners_street_name owners.RESIDENCE%type;
owners_suburb owners.DISTRICT%type;

correct mrs_street_name_translations.CORRECT_NAME%type;
incorrect mrs_street_name_translations.INCORRECT_NAME%type;

amended mrs_street_translation_results.ORIGINAL%type;

/* Used for intermittently commiting records to the database */
counter number;
doCommit number;

/* Declare a cursor to retrieve owner id, owners street name, correct street name
and incorrect street name for any entries where the residence contains an incorrectly
spelled street name as stored in the MRS_STREET_NAME_TRANSLATIONS */
cursor resultsCursor is
select owners.IDENT, owners.RESIDENCE, owners.DISTRICT,
mrs_street_name_translations.CORRECT_NAME, mrs_street_name_translations.INCORRECT_NAME
from owners inner join mrs_street_name_translations
on upper(owners.RESIDENCE) like upper('% '||mrs_street_name_translations.INCORRECT_NAME||' %');

begin

counter := 0;

open resultsCursor;

loop

/* Retrieve each row of the result of the above query into PL/SQL variables*/
fetch resultsCursor into owner_id, owners_street_name, owners_suburb,
correct, incorrect;

/* If there are no more rows to fetch, exit the loop */
exit when resultsCursor%notfound;

if length(owners_street_name) = 40 then

/* Don't amend, just insert as this will stop the script for some reason */
insert into mrs_street_translation_results
values (owner_id, owners_street_name, 'LENGTH IS 40', owners_suburb,
incorrect, correct, 1);

else

/* Replace the incorrect street name in the correct street name */
amended := replace(owners_street_name, upper(incorrect), upper(correct));

/* insert the current tuple */
insert into mrs_street_translation_results
values (owner_id, owners_street_name, amended, owners_suburb,
incorrect, correct, 0);

end if;

/* Increment the counter and get the modulus */
counter := counter +1;
doCommit := mod(counter, 5000);

/* If no remainder then 5000 records have been inserted. Commit */
if doCommit = 0 then
commit;
end if;

end loop;

close resultsCursor;

/* If the amended street address is too large for the table column then replace it with
'VALUE_ERROR' and set the flag */
exception
when VALUE_ERROR then
/* insert the current tuple */
insert into mrs_street_translation_results
values (owner_id, owners_street_name, 'VALUE ERROR', owners_suburb, incorrect,
correct, 1);

end;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 16 2007
4 comments
622 views