游标的使用例子如下:一般在存储过程中
cursor cur_test is select ****(列) from tab_name where ***;--打开游标
if not cur_test%ISOPEN then
open cur_test;
end if;--循环使用游标取出来的数据
loop
fetch cur_test into 变量;
exit when cur_test%NOTFOUND;
......
end loop;
close cur_test; --关闭
cursor cur_test is select ****(列) from tab_name where ***;--打开游标
if not cur_test%ISOPEN then
open cur_test;
end if;--循环使用游标取出来的数据
loop
fetch cur_test into 变量;
exit when cur_test%NOTFOUND;
......
end loop;
close cur_test; --关闭
解决方案 »
- oracle中日期相加减之后的结果都是interval类型?
- windows7安装oracle 内存占用大
- 在oracle导入数据库老是提示用户不存在
- 递归 SQL 级别 1 出现错误
- 给了权限,为什么连接不成功?
- 关于SUM(。。。。。。) OVER(ORDER BY 。。。。。。) 我有问题想请教
- 恢复数据库的脚本该如何写?
- oralce菜鸟都来这里取经吧,高手们都来这里指点吧
- oracle数据导出,但是视图,存储过程,函数,序列等不能导出?
- 数据库发布问题
- C:\>imp system/manager inctype=complete FULL=Y FILE=030718
- 安装oracle8i后,每次起win都出现错误提示 !!!!
SQL> desc customer;
名称 是否为空? 类型
----------------------------------------- -------- --------------
LAST_NAME NOT NULL VARCHAR2(30)
STATE_CD VARCHAR2(2)
SALES NUMBERSQL> select * from customer;LAST_NAME ST SALES
------------------------------ -- ----------
Nicholson ca 6989.99
gdy gd 99999
martin ca 2345.45
Laursen CA 34.34
bambi ca 1234.55
mcgraw nj 123.45已选择6行。 beckhambobo(beckham)很可惜我不会编程
kerisyml(魂之利刃) 你给的例子书里更详细,可是可能因为我没书的环境,怎么试也不成功,所以希望有个成功的使用例子.
lianhg(lianhg)我明白,可还是不成功.例如如下的写法.
SQL> declare
2 lname varchar2(30);
3 ls number;
4 cursor cur_customer is
5 select name,sales from customer where sales=1000;
6 begin
7 open cur_customer;
8 fetch cur_customer into lname, ls;
9 close cur_customer;
10 /
2 lname varchar2(10);
3 ls number;
4 cursor mycursor is select loginid from customer where userid=1502;
5 begin
6 open mycursor;
7 fetch mycursor into lname;
8 dbms_output.put_line(lname);
9 close mycursor;
10* end;
SQL> /
mjb01PL/SQL procedure successfully completed.SQL>
2 lname varchar2(10);
3 ls number;
4 cursor mycursor is select loginid,userid from customer where userid=1502;
5 begin
6 open mycursor;
7 fetch mycursor into lname,ls;
8 dbms_output.put_line(lname||','||ls);
9 close mycursor;
10* end;
SQL> /
mjb01,1502PL/SQL procedure successfully completed.SQL>
8 dbms_output.put_line(lname);
第二句我不明白.如果这不这样用还能怎样用?
作用只是为了打印出fetch的结果而以!