Create Procedure in phpmyadmin

Asked

Viewed 499 times

0

I am trying to create a precedent that changes between Insert and update in phpmyadmin but returns me an error in the line of if EXISTS, then I tried to create by the graphical panel and returns me error in the last line always... Someone knows what’s wrong?

Error when I try the panel (No sql)

inserir a descrição da imagem aqui

Error when I try to sql inserir a descrição da imagem aqui

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 

1 answer

2


You have several syntax errors in this process, 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 ;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.