Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: 2 similar statements, one works, one doesn't. Why?

Re: 2 similar statements, one works, one doesn't. Why?

From: Simon Morley <morleys_at_entcf2.agw.bt.co.uk>
Date: 1997/10/20
Message-ID: <344b7b08.9635885@news.axion.bt.co.uk>#1/1

On Thu, 16 Oct 1997 20:18:54 -0500, rsenn <rsenn_at_capaccess.org> wrote:

>Gentle readers, can someone tell me why one of these statements works
>and the other
>doesn't ? Thanks.
>
>SQL> create or replace procedure test
> 2 is
> 3 begin
> 4 update emp_hist
> 5 set id = 13
> 6 where id = 9999 ;
> 7 end test ;
> 8 /
>
>Procedure created.
>
>SQL> create or replace procedure test
> 2 is
> 3 begin
> 4 select * from emp_hist ;
> 5 -- update emp_hist
> 6 -- set id = 13
> 7 -- where id = 9999 ;
> 8 end test ;
> 9 /
>

If the select is only going to return 1 row you need to declare a variable of type emp_hist%rowtype and select into it

eg

create or replace procedure test is

        myvar emp_hist%rowtype;

begin

        select * into myvar from emp_hist where <condition>;

end;

If the select is going to return multiple rows declare a cursor to hold the result set and process the cursor using open, fetch, close or use a cursor for loop.

eg

create or replace procedure test is

        cursor mycur is select * from emp_hist; begin

	for i in mycur loop
		-- do your processing here
	end loop;

end;

Hope this helps,

Simon Morley. Received on Mon Oct 20 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US