Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 12-Jul-22 21:18pm

I have same situation. Please promote this problem and give us detailed solution.
 
Share this answer
 
Comments
Richard Deeming 13-Jul-22 5:59am    
"Me too" is not a solution to anyone's question.
CHill60 13-Jul-22 7:37am    
What - all that information in Solution 1 not detailed enough for you?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900