[英]MySQL Error 1064 - 'Define Function' Syntax
I am barely learning MySQL (moving from SQLite). 我几乎不学习MySQL(从SQLite迁移)。 I am trying to create a custom function within the MySQL command line client, but am hitting errors that I can't correct - and can't find answers to online.
我正在尝试在MySQL命令行客户端中创建一个自定义函数,但是遇到了无法纠正的错误-无法找到在线答案。 My first function began as this:
我的第一个功能是这样开始的:
CREATE FUNCTION myDatabase.LCASE_ASCII_VALUE_AT(
unparsedLine VARCHAR(1024),
linePos int
) RETURNS int DETERMINISTIC
return ASCII( LCASE( RIGHT( CHAR_LENGTH(unparsedLine) - linePos + 1) ) );
I got this error: 我收到此错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') )' at line 10
Any pointers on where my syntax went wrong? 关于我的语法出错的任何指针? I suspected these, but they didn't fix the problem:
我怀疑了这些,但他们没有解决问题:
return ASCII( LCASE( ...
. But even after manually unraveling the statement, I still got the same error (but on a line in the newly unraveled statement - I leave out the unraveled statement to save space). return ASCII( LCASE( ...
空间)。 DELIMITER $$ [function definition] END $$ DELIMITER ;
DELIMITER $$ [function definition] END $$ DELIMITER ;
business is mandatory - but that didn't fix the error, and MySQL documentation gives an example of a one-line function where DELIMITER is not needed. EDIT: Added that I am creating this function within MySQL command line client. 编辑:添加,我正在MySQL命令行客户端中创建此功能。
right
requires two arguments, the string itself and the number of characters. right
需要两个参数,字符串本身和字符数。 You've only given the character count. 您只给出了字符数。
Try this instead: 尝试以下方法:
return ASCII( LCASE( RIGHT( unparsedLine, CHAR_LENGTH(unparsedLine) - linePos + 1) ) );
Also, you may find that substr
is a better option since there's no need to calculate the argument to right
in that case, something like: 另外,您可能会发现
substr
是一个更好的选择,因为在这种情况下无需计算right
的参数,例如:
return ASCII( LCASE( SUBSTR( unparsedLine, linePos, 1 ) ) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.