请教,如何将以下存储过程转为mysql存储过程。功能是用来获取类似200912061001这样的编号的。如果有自己写的也行。
CREATE PROCEDURE GetSerialNumber
@prefix VARCHAR(50) ='user'
,@SerialNumber VARCHAR(50) ='' output
,@Flag int =0 output
AS
DECLARE @mid VARCHAR(50)
set @mid= CONVERT (VARCHAR(20), GETDATE() , 112)
IF @prefix ='user'
BEGIN
IF exists(select uId FROM users where uId like '%'+@mid+'%')
BEGIN
SET @SerialNumber=@prefix + @mid + cast((SELECT cast(MAX(right(uId,len(@prefix))) as int) + 1 FROM users where uId like '%'+@mid+'%') as varchar(20))
END
ELSE
BEGIN
SET @SerialNumber=@prefix+@mid+cast(1001 as varchar(20))
END
END
ELSE IF @prefix ='product'
BEGIN
IF exists(select pId FROM products where pId like '%'+@mid+'%')
BEGIN
SET @SerialNumber=@prefix+@mid+cast((SELECT cast(MAX(right(pId,len(@prefix))) as int) + 1 FROM products where pId like '%'+@mid+'%') as varchar(20))
END
ELSE
BEGIN
SET @SerialNumber=@prefix+@mid+cast(1001 as varchar(20))
END
END
ELSE
BEGIN
SET @SerialNumber=''
END
PRINT (@SerialNumber)
if @SerialNumber=''
SET @Flag= 0
else
SET @Flag= 1
RETURN @Flag