Error while trying to execute pl/sql that loops through a cursor containing only ROWID's
Вопрос
I'm trying to update all the columns in a given table. This table has ~200,000,000 records in it.
Trying to run a simple update statement doesn't work.
Here is my code:
DECLARE
TYPE ROW_ID_TBL IS TABLE OF ROWID;
CURSOR c_rowIdCursor RETURN ROWID IS
SELECT ROWID FROM SOME_TABLE;
v_RowIDs ROW_ID_TBL;
BEGIN
OPEN c_rowIdCursor;
LOOP
FETCH c_rowIdCursor BULK COLLECT INTO v_RowIDs LIMIT 50000;
EXIT WHEN v_RowIDs.COUNT = 0;
FORALL i IN v_RowIDs.FIRST..v_RowIDs.LAST
UPDATE SOME_TABLE
SET SOME_KEY = MOD(NVL(REGEXP_REPLACE(ALPHA_NUMERIC_VAL, '[^0-9]+', ''), 0), 300)+1
WHERE ROWID = v_RowIDs(i);
COMMIT;
END LOOP;
END;
/
I get the following when I try to run it:
ORA-06550: line 3, column 33:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 3, column 5:
PL/SQL: Item ignored
Решение
Your CURSOR
definition is incorrect. You want something like
CURSOR c_rowIdCursor
IS SELECT ROWID
FROM SOME_TABLE;
Of course, I'm not sure why a simply update wouldn't work. It would be more efficient, it would use fewer resources, and it would require less code.
Не связан с StackOverflow