oracle怎么查询游标,oracle查询游标最大数

Oracle 游标

游标能够根据查询条件从数据表中提取一组记录,将其作为一个临时表置于数据缓冲区中,利用指针逐行对记录数据进行操作。

成都创新互联是专业的聂拉木网站建设公司,聂拉木接单;提供网站建设、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行聂拉木网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

Oracle中的游标分为显示游标和隐式游标 。

在执行SQL语句时,Oracle会自动创建隐式游标,该游标是内存中处理该语句的数据缓冲区,存储了执行SQL语句的结果。通过隐式游标属性可获知SQL语句的执行状态信息。

%found:布尔型属性,如果sql语句至少影响到一行数据,值为true,否则为false。

%notfound:布尔型属性,与%found相反。

%rowcount:数字型属性,返回受sql影响的行数。

%isopen:布尔型属性,当游标已经打开时返回true,游标关闭时则为false。

用户可以显式定义游标。使用显式游标处理数据要4个步骤:定义游标、打开游标、提取游标数据和关闭游标。

游标由游标名称和游标对应的select结果集组成。定义游标应该放在pl/sql程序块的声明部分。

语法格式:cursor 游标名称(参数) is 查询语句

打开游标时,游标会将符合条件的记录送入数据缓冲区,并将指针指向第一条记录。

语法格式:open 游标名称(参数);

将游标中的当前行数据赋给指定的变量或记录变量。

语法格式:fetch 游标名称 into 变量名;

游标一旦使用完毕,就应将其关闭,释放与游标相关联的资源。

语法格式:close 游标名称;

declare

cursor c1 is  select sno,cno,grade from sc;

v_sno sc.sno%type;

v_cno sc.cno%type;

v_grade sc.grade%type;

begin

open c1;

loop

  fetch c1 into v_sno,v_cno,v_grade;

  exit when c1%notfound;--紧跟fetch之后

if c1%found then

dbms_output.put_line(to_char(c1%rowcount)||v_cno);

end if;

end loop;

close c1; 

end;

declare

cursor c1 is select sno,cno,grade from sc;

v_sno sc.sno%type;

v_cno sc.cno%type;

v_grade sc.grade%type;

begin

open c1;

fetch c1 into v_sno,v_cno,v_grade;

while c1%found loop

  dbms_output.put_line(v_sno||v_cno||v_grade);

 fetch c1 into v_sno,v_cno,v_grade;

end loop;

close c1; 

end;

第三种:for

declare

cursor c1 is select sno,cno,grade from sc;

begin

for item in c1 loop

dbms_output.put_line(rpad(item.sno,'10',' ')||rpad(item.cno,'10',' ')||rpad(item.grade,'10',' '));

end loop;

end;

查看oracle已经用了多少游标

select * from v$sysstat where name like '%cursors%'

select * from v$parameter where name like '%cursors%'

select count(0) from v$open_cursor

select sid,count(*) from v$open_cursor group by sid

select count(*),sql_text from v$open_cursor group by sql_text order by count(*) desc

select KGLLKFLG,KGLNAOBJ from X$KGLLK where KGLLKFLG=8;

select max(cursor_count) from (select count(*) cursor_count from v$open_cursor where user_name='CRING_SMS')

在sqlplus中执行

SELECT v.name, v.value value FROM V$PARAMETER v WHERE name = 'open_cursors';

看看value是多少

使用下面的命令可以修改它的大小:

在 oracle9i 中应该可以直接进行修改:

alter system set open_cursors=30000;

如果可以就直接生效了;如果不行可以使用下面的语句:

alter system set open_cursors=30000 scope=spfile;

然后重启数据库生效

Oracle游标查询

SQL select ename,sal from (select * from emp order by sal desc) where rownum=a;

输入 a 的值: 2

原值 1: select ename,sal from (select * from emp order by sal desc) where rownum=a

新值 1: select ename,sal from (select * from emp order by sal desc) where rownum=2

ENAME SAL

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

KING 5000

SCOTT 3000

SQL /

输入 a 的值: 3

原值 1: select ename,sal from (select * from emp order by sal desc) where rownum=a

新值 1: select ename,sal from (select * from emp order by sal desc) where rownum=3

ENAME SAL

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

KING 5000

SCOTT 3000

FORD 3000

oracle存储过程中打开游标有几种方法?用open直接打开?

两种方法\x0d\x0a1.声明游标时写好SELECT语句,如\x0d\x0aCURSOR r_cur1 IS select *** from tableName where 条件;\x0d\x0a使用时\x0d\x0a OPEN r_cur1;\x0d\x0a LOOP\x0d\x0a FETCH *** INTO variable;\x0d\x0a EXIT WHEN r_cur1%NOTFOUND OR r_cur1%NOTFOUND IS NULL;\x0d\x0a。。。\x0d\x0a2.声明游标\x0d\x0accc sys_refcursor;\x0d\x0a使用时\x0d\x0a open ccc for select dept_code,dept_name from comm.dept_dict; \x0d\x0a loop\x0d\x0a fetch ccc into aa,bb;\x0d\x0a exit when ccc%notfound;\x0d\x0a 。。。\x0d\x0a end loop;\x0d\x0a close ccc;


分享题目:oracle怎么查询游标,oracle查询游标最大数
标题链接:http://scyanting.com/article/dsdhhpd.html