【问题标题】:stored procedure, how to handle errorcode: 1062存储过程,如何处理错误代码:1062
【发布时间】:2020-03-08 12:25:17
【问题描述】:


我正在尝试为重复的用户名条目创建一个存储过程处理程序。
该程序设法自己创建它,但是当我将信息输入到表中时,我只能从 mysql 得到标准错误。我该如何解决这个问题?

DELIMITER $$
DROP PROCEDURE IF EXISTS Testproc2$$

create procedure testproc2(filename VARCHAR (40), descriptionn VARCHAR(40),
username VARCHAR(40), firstname VARCHAR(40), lastnameVARCHAR(40), classcode INT(10))

begin
declare exit handler for 1062
    select concat('Feil: username',username,'already exist');
    start transaction;

   insert into bilde 
    values (NULL, filnavn, beskrivelse);

    insert into student 
    values (username, firstname, lastname, classcode, LAST_INSERT_ID());
    commit;

  SELECT CONCAT('Inserted student ',username,' ',firstname' ',lastname' ',classcode' ', LAST_INSERT_ID());
  END$$ 

【问题讨论】:

    标签: mysql stored-procedures error-handling


    【解决方案1】:

    我发现了我的错误,我调用了 testproc1 而不是 testproc2。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 2012-03-23
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多