Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL procedure

Status
Not open for further replies.

ccoa

Programmer
Jun 15, 2006
2
US
Im attempting to write a SQL procedure, unfortunately, since this is my first, it's not going well. This is what I have:

Code:
create procedure restore_from_edit()
begin
  declare done int default 0;
  declare cur1 cursor for (select pe.message, max(pe.editnum), pe.postid from page_edits pe group by pe.pageid);
  declare continue handler for sqlstate '02000' set done = 1;

  open cur1;
 
  repeat
    fetch cur1 into msg, enum, pid;
    if not done then
      update page p set p.pagetext = msg where p.pageid = pid and p.pagetext = '***';
    end if
  until done end repeat
 
  close cur1
end

Unfortunately, I get the following error message:


#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'procedure restore_from_edit
begin
declare done int default 0' at line 1

I would appreciate any help anyone could give me. Thank you.
 
What MySQL version are you using? Stored procedures were only introduced in version 5, I think.
 
It's listed as "4+", which may explain things. I can't think how to write this as an update statement, though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top