游标练习(1027)

来源:互联网 发布:越狱软件哪个好 编辑:程序博客网 时间:2024/04/29 20:32
游标(cursor)是系统为用户开设的一个数据缓冲区,存放SQL语句的执行结果


--方法1declaretype sp_class_user_cursor is ref cursor;test_cursor sp_class_user_cursor;u_xingming s_class_user.xingming%type;u_username s_class_user.username%type;beginopen test_cursor for select t.xingming,t.username from s_class_user t where  t.class_info_id=&no;loopfetch test_cursor into u_xingming,u_username;exit when test_cursor%notfound;dbms_output.put_line('名字:'||u_xingming||'员工编号:'||u_username);end loop;close test_cursor;end;--方法2declarecursor test_easy_cursor is select t.xingming,t.username from s_class_user t where t.class_info_id=&class_id;u_xingming s_class_user.xingming%type;u_username s_class_user.username%type;beginopen test_easy_cursor;loopfetch test_easy_cursor into u_xingming,u_username;exit when test_easy_cursor%notfound;dbms_output.put_line('名字:'||u_xingming||'员工编号:'||u_username);end loop;close test_easy_cursor;end; 

注意:如果控制台只显示PL/SQL procedure successfully completed

没有结果可以尝试输入set serveroutput on size 10000000

来防止ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes




0 0
原创粉丝点击