insert into in stored procedure with parameters MYSQL doesnt work

前端 未结 2 1625
情书的邮戳
情书的邮戳 2020-12-17 03:05

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_         


        
相关标签:
2条回答
  • 2020-12-17 03:17
    DELIMITER $$
    DROP PROCEDURE IF EXISTS `database_name`.`ins`$$
    CREATE DEFINER=`root`@`localhost` PROCEDURE `ins`(in nam varchar(50),in username varchar(50), in branch varchar(50))
    BEGIN
    insert into table_name(nam,user_name,branch) values(nam,username,branch);
        END$$
    DELIMITER ;
    
    call ins('sas','sdsd','sdsd')
    
    0 讨论(0)
  • 2020-12-17 03:31

    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 ;
    
    0 讨论(0)
提交回复
热议问题