Call procedure sql-tool vscode

152 Views Asked by At

I couldn't figure out where the problem is! The procedure is successfully created but the call throws the following error:

Cannot read properties of undefined (reading 'undefined')

Full example:

-- @block
CREATE TABLE index_table(
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    creat_at TimeSTAMP DEFAULT now()
);


-- @block
INSERT INTO index_table(first_name, last_name)
VALUES ('fname1', 'lname1'),
    ('fname2', 'lname2'),
    ('fname3', 'lname3'),
    ('fname4', 'lname4');

-- @block
DROP PROCEDURE if EXISTS  get_table;
CREATE PROCEDURE get_table() 
BEGIN
SELECT 2 ;
END


-- @block
CALL get_table();
1

There are 1 best solutions below

1
Lajos Arpad On

You missed changing the delimiter. Basically, you need to change the delimiter to something else, so the creation of the procedure will be a single command and will not be confounded with the inner commands of the procedure. This is a tested and working version of your code:

-- @block
CREATE TABLE index_table(
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    creat_at TimeSTAMP DEFAULT now()
);


-- @block
INSERT INTO index_table(first_name, last_name)
VALUES ('fname1', 'lname1'),
    ('fname2', 'lname2'),
    ('fname3', 'lname3'),
    ('fname4', 'lname4');

delimiter //

-- @block
DROP PROCEDURE if EXISTS  get_table;
CREATE PROCEDURE get_table() 
BEGIN
SELECT 2 ;
END //

delimiter ;

-- @block
CALL get_table();