How to store selection result in to variable in Oracle procedure

前端 未结 2 1780
失恋的感觉
失恋的感觉 2021-02-08 22:11

I write a simple procedure. I try to store selection result in variable. I use \"SELECT INTO\" query but I can not doing this.

Example:

DECLARE
     v_em         


        
2条回答
  •  心在旅途
    2021-02-08 22:24

    IF your SELECT returns more than one row, you won't be able to use the SELECT INTO synthax.

    You will need to build a loop to navigate through the resulte set:

    Adam demonstrated how you would use an explicit cursor and a bulk collect loop. I will show how you can build the simplest loop possible (implicit cursor, doesn't need a DECLARE section):

    BEGIN
       FOR c_emp IN (SELECT * 
                       FROM Employee 
                      WHERE Salary > 10) LOOP
          /* do something with each row, for example:*/
          UPDATE foo SET bar = bar + c_emp.salary WHERE id = c_emp.id;
       END LOOP;
    END;
    

提交回复
热议问题