如何在 PopSQL 应用程序中使用 DELIMITER 语句?
How to use DELIMITER statement in PopSQL app?
我不得不在 PopSQL 中通过 DELIMITER
语句创建 FUNCTION
和 PROCEDURE
。当我尝试使用 DELIMITER
语句时,该应用程序不断抛出错误:
ER_PARSE_ERROR: 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 'DELIMITER || CREATE FUNCTION count_length(str VARCHAR(255), del VARCHAR(12),' at line 1
下面是我写的一段代码:
DELIMITER ||
CREATE FUNCTION count_length(str VARCHAR(255), del VARCHAR(12), pos INT)
RETURNS VARCHAR(255)
BEGIN
DECLARE getLength;
SET getLength = LENGTH(SUBSTRING_INDEX(str, del, pos - 1)) + 1;
RETURN getLength;
END ||
CREATE PROCEDURE init()
BEGIN
SELECT count_length('Hello|my|name|is|John', '|', 2);
END ||
DELIMITER ;
CALL init();
这是我的数据库设置:
Nickname:
study
Type:
MySQL
Hostname:
localhost
Port:
3325
Database:
study
Username:
root
Password:
none
奇怪的是,上面的代码在 MySQL Workbench.
中运行良好
我正在使用 PopSQL,但不打算使用 Workbench,因为 PopSQL 看起来比 Workbench 更现代、更清晰。
如何在 PopSQL 中使用 DELIMITER
?
delimiter
是 mysql cli command,而不是 sql 语句(在下面的引用中 mysql 指的是 mysql cli,检查链接的 mysql 手册页):
To redefine the mysql delimiter, use the delimiter command. The following example shows how to do this for the dorepeat() procedure just shown. The delimiter is changed to // to enable the entire definition to be passed to the server as a single statement, and then restored to ; before invoking the procedure. This enables the ; delimiter used in the procedure body to be passed through to the server rather than being interpreted by mysql itself.
因此,定界符不能在 popsql 中使用,因为它似乎将所有内容都传递到 mysql 服务器而不试图解释它。
我不得不在 PopSQL 中通过 DELIMITER
语句创建 FUNCTION
和 PROCEDURE
。当我尝试使用 DELIMITER
语句时,该应用程序不断抛出错误:
ER_PARSE_ERROR: 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 'DELIMITER || CREATE FUNCTION count_length(str VARCHAR(255), del VARCHAR(12),' at line 1
下面是我写的一段代码:
DELIMITER ||
CREATE FUNCTION count_length(str VARCHAR(255), del VARCHAR(12), pos INT)
RETURNS VARCHAR(255)
BEGIN
DECLARE getLength;
SET getLength = LENGTH(SUBSTRING_INDEX(str, del, pos - 1)) + 1;
RETURN getLength;
END ||
CREATE PROCEDURE init()
BEGIN
SELECT count_length('Hello|my|name|is|John', '|', 2);
END ||
DELIMITER ;
CALL init();
这是我的数据库设置:
Nickname:
study
Type:
MySQL
Hostname:
localhost
Port:
3325
Database:
study
Username:
root
Password:
none
奇怪的是,上面的代码在 MySQL Workbench.
中运行良好我正在使用 PopSQL,但不打算使用 Workbench,因为 PopSQL 看起来比 Workbench 更现代、更清晰。
如何在 PopSQL 中使用 DELIMITER
?
delimiter
是 mysql cli command,而不是 sql 语句(在下面的引用中 mysql 指的是 mysql cli,检查链接的 mysql 手册页):
To redefine the mysql delimiter, use the delimiter command. The following example shows how to do this for the dorepeat() procedure just shown. The delimiter is changed to // to enable the entire definition to be passed to the server as a single statement, and then restored to ; before invoking the procedure. This enables the ; delimiter used in the procedure body to be passed through to the server rather than being interpreted by mysql itself.
因此,定界符不能在 popsql 中使用,因为它似乎将所有内容都传递到 mysql 服务器而不试图解释它。