我怎样才能把它翻译成mysql?

Posted

技术标签:

【中文标题】我怎样才能把它翻译成mysql?【英文标题】:How can I translate this to mysql? 【发布时间】:2018-03-26 19:43:06 【问题描述】:

我最近从 sql server 迁移到 mysql,但在将我的 sql 存储过程转换为 mysql 存储过程时遇到了麻烦。 这是我的 SQL SERVER 存储过程:

CREATE PROCEDURE dbo.GetGrades  
    @GradeId int = 0
    ,@Name nvarchar(100) = ''
AS
BEGIN   
    SET NOCOUNT ON;


    SELECT ISNULL(I.GradeId,0) as GradeId
      ,ISNULL(I.Name, '') as Name
      ,ISNULL(I.Details, '') as Details
      ,ISNULL(I.StatId, 0) as StatId
      ,ISNULL(I.CreatedById, 0) as CreatedById
      ,ISNULL(U.UserName, '') as CreatedByName
      ,ISNULL(I.CreatedOn, null) as CreatedOn

    FROM Grades I

        LEFT JOIN Users U ON U.UserId = I.CreatedById

    WHERE (I.GradeId = @GradeId OR @GradeId = 0)
      AND (I.Name LIKE '%' + @Name +'%' OR @Name = '')   
      AND I.StatId <> 2 

END

GO

这就是我迄今为止在 mysql 存储过程中所做的:

DELIMITER $$

CREATE PROCEDURE GetGrades
(   
     IN intGradeId INT  
    ,IN strName VARCHAR(1000)       
)
BEGIN
SELECT 
      gradeId
    , gradeName
    , details
    , statId
    , createdById
    , createdOn 
FROM grades 
WHERE (gradeId = intGradeId OR intGradeId = 0)
AND (gradeName LIKE '%' + strName +'%' OR strName = '');
END

当我执行此操作时,这是错误消息:

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '+ strName +'%' OR strName = '')
AND statId = 1;
END' at line 16

另外,mysql中有ISNULL()函数吗?

【问题讨论】:

【参考方案1】:

类似这样的:

DELIMITER $$

CREATE PROCEDURE GetGrades (   
     IN in_intGradeId INT, 
     IN in_strName VARCHAR(1000)       
)
BEGIN
    SELECT gradeId, gradeName, details, statId, createdById, createdOn 
    FROM grades 
    WHERE (gradeId = in_intGradeId OR in_intGradeId = 0) AND
          (gradeName LIKE CONCAT('%', in_strName, '%') OR in_strName = '');
END;

【讨论】:

以上是关于我怎样才能把它翻译成mysql?的主要内容,如果未能解决你的问题,请参考以下文章

翻译,怎样将图片文字翻译成英文

意大利语翻译成中文怎样实现

如何防止谷歌翻译改变我页面的 html 结构?

Laravel 的调试消息 - 部分是法语。我怎样才能把它变成英文?

我怎样才能把它压缩成一个 For 循环?

我如何将此 UDF 翻译成 Pandas UDF