MySQL Forums
Forum List  »  Newbie

Re: Stored Function
Posted by: Peter Brawley
Date: January 02, 2017 04:38PM

Incomplete spec. Does the table have just one row? Otherwise, how is the func to identify which row to update? Assuming it has just the one row ...

drop table if exists master;
create table master( callno int );
insert into master set callno=1;
select callno from master;
drop function if exists callnoincr;
delimiter go
create function callnoincr() returns int deterministic
begin
  declare n int default 0;
  set n = (select callno from master);
  update master set callno=n+1;
  return (select callno from master);
end;
go
delimiter ;
select callnoincr();



Edited 1 time(s). Last edit at 01/02/2017 04:46PM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
January 02, 2017 03:18PM
Re: Stored Function
January 02, 2017 04:38PM
January 02, 2017 05:54PM
January 02, 2017 06:13PM
January 02, 2017 06:30PM
January 02, 2017 07:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.