简体   繁体   中英

Can't create procedure phpMyAdmin MYSQL error

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

If you are using mysql database then try as per below and share error if still getting-

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 ;

Change

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

to

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

by moving as tt to the right place.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM