Can't create procedure phpMyAdmin MYSQL error

时间:2016-02-03 04:29:35

标签: mysql sql stored-procedures mariadb

Help!! I'm stuck, I don't know what's wrong.
I'm working on MySql but it won't create procedure, I'm out of ideas.

CREATE PROCEDURE sc_new_ord(IN inscid INT, IN incust_id INT, IN indeltype_id INT, IN duty_it INT, IN delcost INT, OUT ttmount INT, OUT outordid INT)
BEGIN
  DECLARE ord_id INT;
  DECLARE total INT;

  INSERT INTO tbl_orders (customer_id, ship_type_id, rate_id, status) VALUES
         (incust_id, indeltype_id, duty_it,0);

  SELECT LAST_INSERT_ID() INTO inscid;

  INSERT INTO tbl_ord_det (ord_id,inv_id, item, qtty, price)
  SELECT ord_id, tbl_inventory.Inv_id, tbl_inventory.Item, tbl_shp_ct.qtty,
              COALESCE(NULLIF(tbl_inventory.Offer_Price, 0), tbl_inventory.Price) AS price
  FROM        tbl_shp_ct
  INNER JOIN  tbl_inventory
                ON tbl_shp_ct.inv_id = tbl_inventory.Inv_id
  WHERE tbl_shp_ct.sc_id = inscid AND tbl_shp_ct.buy_now;
    -- total amount
  UPDATE tbl_orders
  SET    tt_mnt = (SELECT SUM(price * qtty)FROM tbl_ord_det WHERE ord_id = ord_id)
  WHERE  ord_id = ord_id;
  CALL sc_empty (inscid);
  SELECT (SUM(price * qtty) FROM tbl_ord_det WHERE  ord_id = ord_id) as tt INTO total;
  SELECT total, delcost, (total+delcost) INTO ttmount;
  SELECT ord_id INTO outordid;
END

Full Error: MySQL said: Documentation

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

2 个答案:

答案 0 :(得分:0)

如果您使用的是mysql数据库,请按以下方式尝试,如果仍然可以分享错误 -

DELIMITER $$
CREATE PROCEDURE sc_new_ord(IN inscid INT, IN incust_id INT, IN indeltype_id INT, IN duty_it INT, IN delcost INT, OUT ttmount INT, OUT outordid INT)
BEGIN
  DECLARE ord_id INT;
  DECLARE total INT;

  INSERT INTO tbl_orders (customer_id, ship_type_id, rate_id, status) VALUES
         (incust_id, indeltype_id, duty_it,0);

  SELECT LAST_INSERT_ID() INTO inscid;

  INSERT INTO tbl_ord_det (ord_id,inv_id, item, qtty, price)
  SELECT ord_id, tbl_inventory.Inv_id, tbl_inventory.Item, tbl_shp_ct.qtty,
              COALESCE(NULLIF(tbl_inventory.Offer_Price, 0), tbl_inventory.Price) AS price
  FROM        tbl_shp_ct
  INNER JOIN  tbl_inventory
                ON tbl_shp_ct.inv_id = tbl_inventory.Inv_id
  WHERE tbl_shp_ct.sc_id = inscid AND tbl_shp_ct.buy_now;
    -- total amount
  UPDATE tbl_orders
  SET    tt_mnt = (SELECT SUM(price * qtty)FROM tbl_ord_det WHERE ord_id = ord_id)
  WHERE  ord_id = ord_id;
  CALL sc_empty (inscid);
  SELECT (SUM(price * qtty) FROM tbl_ord_det WHERE  ord_id = ord_id) as tt INTO total;
  SELECT total, delcost, (total+delcost) INTO ttmount;
  SELECT ord_id INTO outordid;
END$$
DELIMITER ;

答案 1 :(得分:0)

更改

SELECT (SUM(price * qtty) FROM tbl_ord_det WHERE  ord_id = ord_id) as tt INTO total;

SELECT SUM(price * qtty) as tt FROM tbl_ord_det WHERE  ord_id = ord_id INTO total;

as tt移至正确的位置。

http://sqlfiddle.com/#!9/25a842