I have three tables namely Issue, IssueReports and Location with the below structure.
Issue and Location has Many-to-one relationship. Issue and IssueReports are not physically linked but can have some common fields.
IssueReports
-------------
ID (Number);
Issue_Number (Varchar);
Issue_Loc_Name (Varchar)
and some other fields for the report....
Issue
-----------------
ID (Number);
IssueNumber (Varchar);
Issue_Loc_Id (Number)
Location
-----------------
ID (Number);
Loc_Name (Varchar)
I want to update Issue_Loc_Name field in multiple rows of IssueReports with Loc_Name where the IssueNumber of Issue table and IssueNumber of IssueReport table are equal.
I have written the below procedure to update multiple records based on the condition given above, but what I get is the same value for all the Issue_Loc_name of multiple rows of the table IssueReport.
DECLARE
IR_LOCNAME VARCHAR2(10);
IRNUM_TO_SEARCH VARCHAR2(10);
ISNUM_TOSEARCH VARCHAR2(10);
Cursor c1 is select ir.Issue_Number, is.IssueNumber, loc.loc_name
from IssueReports ir, Issue is, Location loc
where loc.id = is.Issue_Loc_Id
AND ir.Issue_Number = is.IssueNumber;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO IRNUM_TO_SEARCH, ISNUM_TOSEARCH, IR_LOCNAME;
DBMS_OUTPUT.put_line(IRNUM_TO_SEARCH || ' ' || ISNUM_TOSEARCH || ' ' || IR_LOCNAME);
EXIT WHEN c1%NOTFOUND;
UPDATE IssueReports SET Issue_Loc_Name = IR_LOCNAME;
WHERE IRNUM_TO_SEARCH = ISNUM_TOSEARCH;
END LOOP;
CLOSE C1;
END;
/
Is there something wrong in my cursor? I am using Oracle 11G.
Best Regards, MouliPC.