I have a table valued function in SQL which is working fine now i want same function to be used in MYSql but im not able to create this function in MySQL as there is no Table valued functions in MySQL i have tried using Store procedure but i want to use the output in another sp for which i can not use select * from that store procedure
Please suggest some alter native
Here is my sql function which i want in MySQL
What I have tried:
ALTER FUNCTION [dbo].[TextSplit]
(
@Text VARCHAR(max),
@Delimiter VARCHAR(1)
)
RETURNS @SplitData TABLE
(
Position INT IDENTITY PRIMARY KEY,
Value VARCHAR(max)
)
AS
BEGIN
DECLARE @index int
-- SET @Text = REPLACE(@Text, ' ', '')
SET @index = -1
WHILE (LEN(@Text) > 0)
BEGIN
SET @index = CHARINDEX(@Delimiter , @Text)
IF (@index = 0) AND (LEN(@Text) > 0)
BEGIN
INSERT INTO @SplitData VALUES (@Text)
BREAK
END
IF (@index > 1)
BEGIN
INSERT INTO @SplitData VALUES (LEFT(@Text, @index - 1))
SET @Text = RIGHT(@Text, (LEN(@Text) - @index))
END
ELSE
SET @Text = RIGHT(@Text, (LEN(@Text) - @index))
END
RETURN
END
If we pass this values
SELECT * FROM [dbo].[TextSplit]('2009-2010', '-')
the function returns following output
Position Value
1 2009
2 2010