Home > Database > Mysql Tutorial > body text

Oracle PLSQL 在游标中用while循环实例程序

WBOY
Release: 2016-06-07 17:45:52
Original
1172 people have browsed it

Oracle PLSQL 在游标中用while循环实例程序

Oracle PLSQL 在游标中用while循环实例程序

Oracle PLSQL 在游标中用while循环实例程序

declare
 cursor emp_cur is select * from emp;
 v_emp emp%rowType;
 begin
 open emp_cur;
 
 while emp_cur%notfound --while肯定要跟loop一起用的 且是控制循环体的
loop
 fetch emp_cur into v_emp;
 dbms_output.put_line(v_emp.ename);

 end loop;
 close emp_cur;
 end;

//实例二

关于cursor循环,有两种方式:
1. 使用loop, exit (不用while)
如:
 loop
 fetch emp_cur into v_emp;
 exit when emp_cur%notfound;
 dbms_output.put_line(v_emp.ename);
 end loop;
2. 使用while, 这时先要fetch
 fetch emp_cur into v_emp;
 while (emp_cur%found)
 loop
  dbms_output.put_line(v_emp.ename);
  fetch emp_cur into v_emp;
 end loop; 

?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!