我试图写一个存储的过程,输入发票号。 和日期,并尝试将日期更新为表格行。 如果成功,则应返回1,如果失败则应返回0。我的代码如下。 我得到的是它总是返回1,但仅在日期有效时才更新表。 如果更新不成功,我希望它返回0。 感谢任何帮助,谢谢。

CREATE DEFINER=`root`@`localhost` FUNCTION `invoice_paid_date`(`inv_no` INT,    
     `date_paid` DATE)
  RETURNS SMALLINT
  LANGUAGE SQL
  DETERMINISTIC
  CONTAINS SQL
  SQL SECURITY DEFINER
  COMMENT 'attempt to update paid_date in table invoice'
BEGIN
   declare exit handler for sqlwarning, sqlexception  return 0;
   update invoice set paid_date = date_paid where invoice_no = inv_no;
return 1;
END

===============>>#1 票数:0

尝试这个:

CREATE DEFINER=`root`@`localhost` FUNCTION `invoice_paid_date`(`inv_no` INT,    
         `date_paid` DATE)
      RETURNS SMALLINT
      LANGUAGE SQL
      DETERMINISTIC
      CONTAINS SQL
      SQL SECURITY DEFINER
      COMMENT 'attempt to update paid_date in table invoice'
    BEGIN
       DECLARE id INT DEFAULT 1;
       DECLARE EXIT HANDLER FOR SQLEXCEPTION SQLWARNING
       BEGIN
           SET id = 0;
           RETURN 0;
       END;

       IF id = 1 THEN
           update invoice set paid_date = date_paid where invoice_no = inv_no;
           return 1;
       END IF;
    END

  ask by user3152824 translate from so

未解决问题?本站智能推荐: