mysql stored procedure select and update selected -


i trying write stored procedure mysql, , basicly, select 1 id, , update selected id's operationdate.

delimiter //  create procedure getid(   in proc_intervaldate datetime  )   begin     declare ruserid bigint;     select          userid      ruserid      tasks      operationdate < proc_intervaldate     limit 1 ;      update tasks set operationdate = now() userid = ruserid;      select ruserid ;    end // delimiter ; 

but when use this, procedure, return userid not update, if comment

select ruserid 

then, updates, no data returns.

when use this, procedure, return userid not update, if comment 'select ruserid;' then, updates, no data returns.

you can change definition of stored procedure use out parameter rather in. that, can capture out value on same out parameter, in scripting language. meaning need not execute:

select ruserid ; 

in stored procedure.

change sp definition below:

delimiter // create procedure getid( in proc_intervaldate datetime, out ruserid bigint ) begin     select        userid ruserid      tasks            operationdate < proc_intervaldate     limit 1 ;      update tasks set operationdate = now() userid = ruserid; end; // delimiter ; 

you can call stored procedure like, example, @ mysql console:

set @ruserid := 0; call getid( now(), @ruserid ); select @ruserid; 

refer to:

  • mysql: call procedure syntax
    • to value procedure using out or inout parameter, pass parameter means of user variable, , check value of variable after procedure returns.

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -