I'm stuck to create FUNCTION
and PROCEDURE
through DELIMITER
statement in PopSQL. The app keeps throwing an error when I try to use DELIMITER
statement:
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
The following is a code what I wrote:
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();
And this is my DB setting:
Nickname:
study
Type:
MySQL
Hostname:
localhost
Port:
3325
Database:
study
Username:
root
Password:
none
A weird thing is, the code above works fine in MySQL Workbench.
I'm using PopSQL and have no plan to use Workbench, because PopSQL looks more modern and clearer then Workbench.
How to use DELIMITER
in PopSQL?
delimiter
is a mysql cli command, not an sql statement (in the quote below mysql refers to mysql cli, check the linked mysql manual page):
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.
Therefore, delimiter cannot be used in popsql as it seems to pass everything through to the mysql server without trying to interpret it.