1

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();
Jaafar Melhem
  • 157
  • 1
  • 7

1 Answers1

0

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();

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • The error is in the call procedure... I think in the SQLTools extension no need for delimiter .. after I create the procedure in vs code ,I run it on MySQL command line.. it work without any problems ..in the vs code it throw an error ! – Jaafar Melhem Jan 30 '23 at 01:19