游标使用—return

来源:互联网 发布:apk文件数据库提取 编辑:程序博客网 时间:2024/06/18 15:23

游标使用

 

在游标中要想只是显示一条结果,则可用return返回。

 declare

  cursor c_copy_dept(c_dept_id number) is

  select dp.department_name from bi_pub.dim_department dp

  where dp.department_id=c_dept_id;

  c_dept c_copy_dept%rowtype;

  begin

    open c_copy_dept(2001);

    fetch c_copy_dept into  c_dept;

    while c_copy_dept%found loop

     

      dbms_output.put_line('re'||c_dept.department_name);

      return;

      end loop;

     

      end;

 

在游标中,可以把游标的取值赋给申明的一个变量。

declare

v_name varchar(50);

  cursor c_copy_dept(c_dept_id number) is

  select dp.department_name from bi_pub.dim_department dp

  where dp.department_id=c_dept_id;

  c_dept c_copy_dept%rowtype;

  begin

    open c_copy_dept(2001);

    fetch c_copy_dept into  c_dept;

    while c_copy_dept%found loop

      v_name:=c_dept.department_name;

      dbms_output.put_line('re'||v_name);

      return;

      end loop;

     

      end;

 

原创粉丝点击