Oracle's Stored Procedure Programming Lecture 9: The Use of Implicit Cursors

Example 1:



 

-----------------------------------------------------------------------------------------------------------------

declare

 

begin

   for emp_record in(select * from emp)

     loop

       dbms_output.put_line('Name: '||emp_record.ename||' Department ID: '||emp_record.ename);

     end loop;

  

end;

-------------------------------------------------------------------------------------------------------------------

 

 

Example 2:

----------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------ 

declare

 

begin

   update emp set sal=sal*(1+0.2) where job='SALESMAN';

   if sql%notfound then -- if the update statement does not affect any row of data, execute

      dbms_output.put_line('No employee needs salary increase');

   else--If the update statement affects at least one row of data, execute

      dbms_output.put_line('Yes'||sql%rowcount||'The salary of employees is increased by 20%');

  end if;

  

end;

------------------------------------------------------------------------------------------------------------------------- 

 

 

When executing SELECT , INSERT , DELETE and UPDATE statements in a PL/SQL block , Oracle allocates a context area ( Context Area ), a buffer, in memory. The cursor is a pointer to the area , or named a work area ( Work Area ), or a structured data type.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326607104&siteId=291194637