问题
I have created a procedure which finds some records with a missing date which needs to be populated. I have written a cursor which uses a select statement to find these records and was going to use a for loop to update them.
There is an existing public function in the application that will return the date I need if I pass the ID of the record to it . My question is a syntax one really, how do I call this public function in a cursor for loop and pass the variable I need to it to get the date back then update the records that I have found in the cursor select statement.
The procedure I have written looks a bit like this:
CREATE OR REPLACE PROCEDURE PRO_POPMISSINGDATE IS
CURSOR cur_FindMissingDate IS
SELECT fieldID,
field2,
field3
FROM table1
table2
table3
WHERE CONDITION 1
CONDITION 2
CONDITION 3
BEGIN
FOR rec_cur_FindMissingDate IN cur_FindMissingDate
LOOP
BEGIN
UPDATE TABLE2
SET missingdate = fnc_get_date(fieldID);
WHERE field2 = field4
COMMIT;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error updating record ' || SUBSTR(SQLERRM, 1, 250));
ROLLBACK;
END;
END LOOP;
END PRO_POPMISSINGDATE;
I am getting an ORA-00904 invalid identifier error in the update statement as it doesnt recognise fieldID. I have evidently done something totally wrong here but I have hit a mental block, any advice would be much appreciated
回答1:
I think you mean:
SET missingdate = fnc_get_date(rec_cur_FindMissingDate.fieldID);
来源:https://stackoverflow.com/questions/13729362/call-a-function-in-a-cursor-for-loop