Create procedure in phpmyadmin

0

I'm trying to create a procedure that changes between insert and update in phpmyadmin but it returns an error in the line of if EXISTS, then I tried to create it by the graphical panel and it returns error in the last line always ... Does anyone know what's wrong?

Error when I try the panel (Without sql)

Errorwhentryingpersql

Query

CREATE PROCEDURE SEND_ITEMS(
  IN i_item_id int(11), 
  IN i_customer_id VARCHAR(11),
  IN i_quantity SMALLINT)
  AS
  BEGIN
  IF(EXISTS(SELECT item_id,customer_id FROM wpcheap_items_selected WHERE (item_id = i_item_id AND customer_id = i_customer_id)))
 THEN Update wpcheap_items_selected SET quantity = i_quantity WHERE (item_id = i_item_id AND customer_id = i_customer_id)
 ELSE 
   INSERT INTO wpcheap_items_selected(item_id,customer_id,quantity) VALUES (i_item_id, i_customer_id, i_quantity)
END 
    
asked by anonymous 13.12.2017 / 15:23

1 answer

2

You have several syntax errors in this procedure, follow the correct code: Some were missing;

DROP PROCEDURE IF EXISTS SEND_ITEMS;
DELIMITER |
CREATE PROCEDURE SEND_ITEMS(
        IN i_item_id int(11), 
        IN i_customer_id VARCHAR(11),
        IN i_quantity SMALLINT
)
BEGIN
    IF(EXISTS(SELECT item_id,customer_id FROM wpcheap_items_selected WHERE (item_id = i_item_id AND customer_id = i_customer_id))) THEN

        UPDATE wpcheap_items_selected 
            SET quantity = i_quantity 
        WHERE (item_id = i_item_id 
            AND customer_id = i_customer_id);

     ELSE 

         INSERT INTO wpcheap_items_selected(
                item_id,
                customer_id,
                quantity) 
        VALUES (
                i_item_id, 
                i_customer_id, 
                i_quantity);

    END IF;
END 
|
DELIMITER ;
    
13.12.2017 / 15:49