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

前端 未结 4 1371
故里飘歌
故里飘歌 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:31

    CREATE PROCEDURE a_proc
    AS
        CURSOR names_cur IS
            SELECT  student_name
            FROM    student.student_details
            WHERE   class_id = 'C';
    
        names_t  names_cur%ROWTYPE;
        TYPE names_ntt IS TABLE OF names_t%TYPE; -- must use type
        l_names  names_ntt;
    BEGIN
        OPEN  names_cur;
        FETCH names_cur BULK COLLECT INTO l_names;
        CLOSE names_cur;
    
        FOR indx IN 1..l_names.COUNT LOOP
            DBMS_OUTPUT.PUT_LINE(l_names(indx).student_name);
        END LOOP;
    END a_proc;
    

提交回复
热议问题