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

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

    Hi all and Thank you for your time. I have resolved the question and all thanks to Ederson.

    Here is the solution :

    SELECT WM_CONCAT(STUDENT_NAME) 
    FROM STUDENT.STUDENT_DETAILS WHERE CLASS_ID= 'C';
    

    Now if you are using this in a stored procedure or PLSQL you just have to create a variable and use SELECT INTO with it and print the variable.

    Here is the code

    DECLARE
    
    C_NAMES VARCHAR2(100);
    
    BEGIN
    
       SELECT WM_CONCAT(STUDENT_NAME) INTO C_NAMES
       FROM STUDENT.STUDENT_DETAILS WHERE CLASS_ID= 'C';
    
      dbms_output.put_line(sname);
    
    END;
    

    Thanks again for your help people.

提交回复
热议问题