Home » SQL & PL/SQL » SQL & PL/SQL » How to use cursors
How to use cursors [message #205273] Fri, 24 November 2006 02:32 Go to next message
karrisql.com
Messages: 7
Registered: November 2006
Junior Member
Hi,

I have make cursor, like:
declare
first varchar2(20);
second varchar2(20);

CURSOR get_message_cur
IS SELECT FIRST, SECOND FROM TABLE;

BEGIN

OPEN get_message
LOOP
FETCH get_message_cur INTO
first, second;
EXIT WHEN get_message_cur%NOTFOUND;
END LOOP;

CLOSE get_message_cur;

How can I use it?

BR K
Re: How to use cursors [message #205276 is a reply to message #205273] Fri, 24 November 2006 02:37 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,

do you mean to display it.[code not tested].

declare
first varchar2(20);
second varchar2(20);

CURSOR get_message_cur
IS SELECT FIRST, SECOND FROM TABLE;

BEGIN

OPEN get_message
LOOP
FETCH get_message_cur INTO first, second;
EXIT WHEN get_message_cur%NOTFOUND;
dbms_output.put_line(get_message.first||','||get_message.second);
END LOOP;

CLOSE get_message_cur;

end;


regards,

[Updated on: Fri, 24 November 2006 02:38]

Report message to a moderator

Re: How to use cursors [message #205311 is a reply to message #205273] Fri, 24 November 2006 04:16 Go to previous messageGo to next message
moparthy99
Messages: 13
Registered: July 2006
Junior Member
declare
first varchar2(20);
second varchar2(20);
CURSOR get_message_cur
IS SELECT FIRST, SECOND FROM TABLE;
BEGIN
OPEN get_message_cur
LOOP
FETCH get_message_cur INTO
first, second;
EXIT WHEN get_message_cur%NOTFOUND;
here we got the values first and second variable values then
u can process or just print use dbms stmt
END LOOP;
close get_message_cur;
end;


afeter simply run block .i hope it is fine
Re: How to use cursors [message #205319 is a reply to message #205311] Fri, 24 November 2006 04:42 Go to previous message
Ferrarist
Messages: 29
Registered: March 2006
Location: Netherlands - Den Haag
Junior Member
Just a little remark...

You can't use FIRST as a user defined variable it's a reserved word. Cool

Regz,
Rob
Previous Topic: oracle error
Next Topic: CURSORS
Goto Forum:
  


Current Time: Fri Dec 02 20:56:58 CST 2016

Total time taken to generate the page: 0.08739 seconds