Thursday, November 4, 2010

Looping Through CURSOR

Note: Cursor is basically a representation of the result set generated from an SQL; this example shows how to loop through that result set and access its values

  PROCEDURE delete_loan_type_history_pr (i_loan_type_code IN XXHLS.XXHLS_LOAN_TYPE_LIST.LOAN_TYPE_CODE%TYPE)
 
    IS
   
    BEGIN
   
        FOR l_cursor IN (SELECT LOAN_TYPE_HISTORY_ID
                         FROM   XXHLS.XXHLS_LOAN_TYPE_HISTORY
                         WHERE  LOAN_TYPE_CODE = i_loan_type_code)
        LOOP
            -- delete documents
            delete_loan_docs_applied_pr(l_cursor.LOAN_TYPE_HISTORY_ID);
            -- delete history record
            DELETE FROM XXHLS.XXHLS_LOAN_TYPE_HISTORY
            WHERE LOAN_TYPE_HISTORY_ID = l_cursor.LOAN_TYPE_HISTORY_ID;
           
        END LOOP;

    END delete_loan_type_history_pr;

No comments:

Post a Comment