Re: Cursor concept
- From: "Michel Cadot" <micadot{at}altern{dot}org>
- Date: Thu, 8 Dec 2005 07:16:21 +0100
"Gerard Lacroix" <kochel_verz@xxxxxxxxx> a écrit dans le message de news: 1134005308.764144.78180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Hi !
| I tried to show a friend that pl/sql cursors are in fact pointers and
| do not retrive all rows when you open them. So I made this very simple
| test case, but I don't understand the output. I think the answer comes
| from the multiversioning side, but I 'd like to understand clearly this
| case with a cursor. May be it is not just a memory position isn't it ?
|
| Thanks.
|
| C:\>sqlplus scott/tiger
|
| SQL*Plus: Release 9.2.0.1.0 - Production on Wed Dec 7 22:40:55 2005
|
| Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
|
|
| Connected to:
| Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
| With the Partitioning, OLAP and Oracle Data Mining options
| JServer Release 9.2.0.1.0 - Production
|
| SQL> create table t as select rownum a from user_objects where rownum <
| 10;
|
| Table created.
|
| SQL> declare
| 1 cursor cur_test is
| 2 select a
| 3 from t
| 4 order by a;
| 5 v_test t.a%type;
| 6 cont boolean := TRUE;
| 7 begin
| 8 open cur_test;
| 9 loop
| 10 fetch cur_test into v_test;
| 11 exit when cur_test%notfound;
| 12 if cont then
| 13 begin
| 14 delete from t where a = 9;
| 15 cont := FALSE;
| 16 commit;
| 17 end;
| 18 end if;
| 19 dbms_output.put_line(v_test);
| 20 end loop;
| 21 close cur_test;
| 22 end;
| 23 /
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
|
| PL/SQL procedure successfully completed.
|
You don't what you don't understand. Is this "why there is 9 in output?"?
1) Oracle guarantees the result of a query/cursor at the time it is opened.
In your case before the delete, so 9 is in the (virtual) result set.
2) Moreover, as you have an "order by" clause in your clause, the result is
actually materialized in sort segments and fetches come from these ones.
Regards
Michel Cadot
.
- References:
- Cursor concept
- From: Gerard Lacroix
- Cursor concept
- Prev by Date: Re: Can you pass a table name into a stored procedure?
- Next by Date: Re: Oracle issues after switching from a workgroup to domain
- Previous by thread: Cursor concept
- Next by thread: Re: Cursor concept
- Index(es):
Relevant Pages
- RE: Oracle cursor help
... rids dbms_utility.uncl_array; ... where <your where clause> ...
Subject: Re: Oracle cursor help ... exit the loop: */ ... (perl.dbi.users) - Cursor concept
... I tried to show a friend that pl/sql cursors are in fact pointers and ... case
with a cursor. ... SQL> create table t as select rownum a from user_objects where
rownum < ... 20 end loop; ... (comp.databases.oracle.misc) - Re: Cursor concept
... > I tried to show a friend that pl/sql cursors are in fact pointers and ...
> case with a cursor. ... regardless of how long the query has been running.
... (comp.databases.oracle.misc) - Command object stops prematurely without error?
... However, when run via the ADO Command object, the outer loop Applications ...
Declare cApps CURSOR for Select ApplicationID from UCM_Applications ... (microsoft.public.data.ado) - Re: Calling a SP inside a cursor loop..
... every loop iteration of the cursor. ... Fetch next From EffectiveDate_Cursor
Into @FLD1,@FLD2 ... and If the Fetch stmt is below the begin Stmt, the loop iterations
are ... the proper way to program a cursor loop is: ... (comp.databases.ms-sqlserver)