Fetch MULTIPLE ROWS and STORE in 1 VARIABLE - ORACLE STORED PROCEDURE

前端 未结 4 1406
故里飘歌
故里飘歌 2021-02-06 00:55

I am working on ORACLE STORED PROCEDURES and I have a doubt. I have a query which fetches more than 1 row and I want to store all those 3 row\'s values in 1 Variable. Can anybod

4条回答
  •  春和景丽
    2021-02-06 01:13

    You'll need a cursor for that:

    DECLARE
        CURSOR stud_cur IS
        SELECT STUDENT_NAME FROM STUDENT.STUDENT_DETAILS WHERE CLASS_ID= 'C';
    
        l_stud STUDENT.STUDENT_DETAILS%ROWTYPE;
        BEGIN
          OPEN stud_cur;
          LOOP
            FETCH stud_cur INTO l_stud;
            EXIT WHEN stud_cur%NOTFOUND;
    
            /* The first time, stud_cur.STUDENT_NAME will be Jack, then Jill... */
          END LOOP;
        CLOSE stud_cur;
    END;
    

提交回复
热议问题