procedure.sql 437 B

1234567891011
  1. drop procedure if EXISTS autodecrement;
  2. delimiter $$
  3. CREATE PROCEDURE autodecrement(IN tableName VARCHAR(50),IN fieldName VARCHAR(20),IN id int,IN action VARCHAR(10),IN step int,OUT result int)
  4. BEGIN
  5. set @sql = concat('update ',tableName,' set ',fieldName,' = ',fieldName,action,step,' where id = ',id,' and ',fieldName,action,step,' > 0');
  6. prepare stmt from @sql;
  7. execute stmt;
  8. select ROW_COUNT() into result;
  9. END$$
  10. delimiter;