Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

insert into in stored procedure with parameters MYSQL doesnt work

i am trying to make a stored procedure with parameters using mysql workbench to insert data into a table.

what am i doing wrong??

    USE deb42181_ramos;
CREATE PROCEDURE sp_insertuser(IN gebruikersnaamparam varchar(10)
, IN wachtwoordparam VARCHAR(50)
, IN voornaamparam VARCHAR(15)
, IN achternaamparam VARCHAR(15)
, IN tussenvoegselparam VARCHAR(10)
, IN gebruikerlevelparam INT)
BEGIN

INSERT INTO gebruikers (
gebruikersnaam
, wachtwoord
, voornaam
, achternaam
, tussenvoegsel
, gebruikerlevel)

    VALUES (gebruikersnaamparam
    , wachtwoordparam
    , voornaamparam
    , achternaamparam
    , tussenvoegselparam
    , gebruikerlevelparam);

END

the error is in the last row of the values after ) he doesnt expect a ;
regards Jeroen

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to change the delimiter, like this:

# change the delimiter to $$, so you can use semicolon in create procedure
DELIMITER $$

USE deb42181_ramos$$

DROP PROCEDURE IF EXISTS sp_insertuser$$

CREATE PROCEDURE sp_insertuser(IN gebruikersnaamparam varchar(10)
, IN wachtwoordparam VARCHAR(50)
, IN voornaamparam VARCHAR(15)
, IN achternaamparam VARCHAR(15)
, IN tussenvoegselparam VARCHAR(10)
, IN gebruikerlevelparam INT)
BEGIN

INSERT INTO gebruikers (
gebruikersnaam
, wachtwoord
, voornaam
, achternaam
, tussenvoegsel
, gebruikerlevel)

    VALUES (gebruikersnaamparam
    , wachtwoordparam
    , voornaamparam
    , achternaamparam
    , tussenvoegselparam
    , gebruikerlevelparam);

END$$
# change the delimiter back to semicolon
DELIMITER ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...