SQL:REVERSE FUNCTION

时间:2017-12-26 21:36:23

标签: mysql

我想在不使用反向命令的情况下反转给定的字符串是SQL any   答案
    反向('串样本)     来自emp

1 个答案:

答案 0 :(得分:0)

http://www.c-sharpcorner.com/code/1308/reverse-string-in-sql-server-without-reverse-function.aspx提供,但使用SQL Server

CREATE function StringReverse(@inputstring varchar(max))  
returns varchar(max)   
AS  
BEGIN  
  DECLARE @i int,   
          @Result varchar(max)  
  SET @Result=''  
  SET @i = 1  
  WHILE @i <= LEN(@inputstring)  
  BEGIN  
    SET @Result = SUBSTRING(@inputstring,@i,1) + @Result  
    SET @i=@i + 1  
  END  
  RETURN @Result 
END