如何将MsSql过程转换为以XML形式检索数据的MySql

时间:2018-10-17 08:06:14

标签: mysql xml

这是我在MsSql中的存储过程。我想转换为MySql。输出必须为XML。 这是一个简单的过程,可通过输入用户名和密码来确定登录是否成功。 任何帮助将不胜感激。

CREATE PROCEDURE [dbo].[P_LOGIN_VALIDATION]
    @p_in_username VARCHAR(100),
    @p_in_password varchar(255),
    @p_out_response_data VARCHAR(MAX) OUTPUT
AS
  BEGIN
  BEGIN TRY
---SUCCESSFUL VALIDATION    
IF EXISTS(SELECT * FROM [dbo].[USERS] WHERE 
UPPER(TRIM(DASHBOARD_USER_NAME)) = UPPER(TRIM(@p_in_username)) AND [PASSWORD] = @p_in_password and IS_VALID_TO > GETDATE())
BEGIN
    SELECT @p_out_response_data = t1.XmlData from (select CAST((Select U.*,'SUCCESS' AS STATUS FROM [USERS] U WHERE 
    UPPER(TRIM(DASHBOARD_USER_NAME)) = UPPER(TRIM(@p_in_username))
    FOR XML PATH(''), ROOT ('ResponseData')) AS VARCHAR(MAX)) AS XmlData) t1;
END
ELSE
    BEGIN

    -- USER NOT EXISTS  
    IF NOT EXISTS(  SELECT 1   
                    FROM [dbo].[USERS]  
                    WHERE UPPER(TRIM(DASHBOARD_USER_NAME)) = UPPER(TRIM(@p_in_username)) )  
            BEGIN 
                SELECT @p_out_response_data = t1.XmlData from (select CAST((Select 'ERROR' As STATUS,'Username doesnot exist' As REMARKS 
                FOR XML PATH(''), ROOT ('ResponseData')) AS VARCHAR(MAX)) AS XmlData) t1;               
                RETURN;
            END    

    END
    END TRY
    BEGIN CATCH
        SELECT @p_out_response_data = t1.XmlData from (select CAST((Select 'ERROR' As STATUS,ERROR_MESSAGE() As REMARKS 
        FOR XML PATH(''), ROOT ('ResponseData')) AS VARCHAR(MAX)) AS XmlData) t1;
    END CATCH
END
GO

0 个答案:

没有答案