Re: ORA-06550: declaring cursor inside "begin/end" structure of PL/SQL block




strepxe@xxxxxxxxxxx wrote:
> This is a newbie question so please don't be too annoyed if the
> question is trivial or the method I'm using is inefficient. I'm keen to
> learn!
>
> I've written PL/SQL which gets a lists of values into a cursor. That
> list of values is then used in a loop to create another cursor
> containing LONG RAW values which I'm trying to get the size of for some
> capacity planning activites.
>
> Here's the basic structure:
>
> DECLARE
> CURSOR1
> BEGIN
> LOOP1
> CURSOR2
> LOOP2
> END LOOP2
> END LOOP1
> END
>
> Here's the PL/SQL itself:
>
> ----------------------------------------------------------------------------------------------------------------------------------
> set serveroutput on
>
> declare
>
> v_longcol long raw;
> v_size number(8,3) not null := 0;
> v_name varchar(100);
> r_count number not null := 0;
>
> cursor get_str is select name from tbl1;
>
> begin
>
> for v_name in get_str
> loop
> cursor get_row is select col1 from tbl2 where stream_name =
> 'v_name.name';
>
> open get_row;
> fetch get_row into v_longcol;
> loop
> exit when get_row%notfound;
>
> v_size := utl_raw.length(v_longcol) / 1024 ;
> ...
> ....
> ...
>
> fetch get_row into v_longcol;
> end loop;
> close get_row;
> end loop;
>
> end;
> /
> ----------------------------------------------------------------------------------------------------------------------------------
>
> When I run the block I get the following error:
>
> ----------------------------------------------------------------------------------------------------------------------------------
>
> cursor get_row is select col1 from tbl2 where stream_name =
> 'v_name.name';
> *
> ERROR at line 23:
> ORA-06550: line 23, column 9:
> PLS-00103: Encountered the symbol "GET_ROW" when expecting one of the
> following:
> := . ( @ % ;
>
> ----------------------------------------------------------------------------------------------------------------------------------
>
> I'm aware of the limitations of cusors from a basic point of view. I
> guess I need some way to generate cusors in another way inside the
> loop.
>
> Any help very much appreciated!


This is how you should have written it:

declare

v_longcol long raw;
v_size number(8,3) not null := 0;
r_count number not null := 0;

cursor get_str is select name from tbl1;
cursor get_row (v_nme in varchar2) is select col1 from tbl2 where
stream_name =
v_nme;



begin

for v_name in get_str
loop
open get_row(v_name.name);
fetch get_row into v_longcol;
loop
exit when get_row%notfound;

v_size := utl_raw.length(v_longcol) / 1024 ;
...
....
...

fetch get_row into v_longcol;
end loop;
close get_row;
end loop;

end;
/

Note the cursor declaration is in the 'declare' section, where it
should be, and note also you've coded the second cursor to accept a
parameter, to pass the value from the first cursor to the second.


David Fitzjarrell

.



Relevant Pages

  • Re: Cursor loop
    ... I've created a stored procedure that loops through a cursor, ... DECLARE curPeriod CURSOR LOCAL for SELECT * FROM tblPeriods ... The problem is that this loop only executes one time, ...
    (comp.databases.ms-sqlserver)
  • Re: ORA-06550: declaring cursor inside "begin/end" structure of PL/SQL block
    ... > This is a newbie question so please don't be too annoyed if the ... > I've written PL/SQL which gets a lists of values into a cursor. ... > list of values is then used in a loop to create another cursor ... > DECLARE ...
    (comp.databases.oracle.server)
  • Opening cursor after closing does not seem to requery
    ... I declare a cursor, then enter a loop. ... opens at the same row as the initial opening, ...
    (microsoft.public.sqlserver.programming)
  • Loop with Read Only cursor?
    ... loop, a few days ago. ... but I don't know how to declare a read only cursor. ... I had 2 columns - a RowNum col and ...
    (microsoft.public.inetserver.asp.general)
  • ORA-06550: declaring cursor inside "begin/end" structure of PL/SQL block
    ... This is a newbie question so please don't be too annoyed if the ... I've written PL/SQL which gets a lists of values into a cursor. ... list of values is then used in a loop to create another cursor ... I'm aware of the limitations of cusors from a basic point of view. ...
    (comp.databases.oracle.server)