简体   繁体   中英

SQL IBM DB2 (Windows 10) not reading end if; (stored procedure)

I'm getting this error for my stored procedure. My ibm db2 doesn't seem to be reading the END IF; statement.

I'm using Windows 10 for my db2.

Error message:

SQL0104N An unexpected token "END@" was found following "_Details)". Expected tokens may include: "END IF".

My code:

CREATE PROCEDURE SeatPricing (IN seat_num varchar(2), ticket_id varchar(10))
BEGIN 
    IF seat_num LIKE 'A_' THEN
    UPDATE Ticket_Details 
    SET seat_price = 500.00
    WHERE ticket_id = (SELECT ticket_id
                       FROM Ticket_Details);
    UPDATE Ticket 
    SET seat_price = 500.00
    WHERE ticket_id = (SELECT ticket_id
                       FROM Ticket);
  ELSE 
    UPDATE Ticket_Details
    SET seat_price = 300.00
    WHERE ticket_id = (SELECT ticket_id
                       FROM Ticket_Details);
    UPDATE Ticket
    SET seat_price = 300.00
    WHERE ticket_id = (SELECT ticket_id
                       FROM Ticket);
    END IF;
 END@
 /

You have multiple problem into your stored procedure:

  1. @ to the end
  2. You dont use ticket_id into your updates
  3. You update all your tables, your where are not necessary. When you do it: "where id = id (when you do ticket_id = (SELECT ticket_id FROM Ticket)" your take all ticket id I think.
  4. Your if do the same query but change only one parameter, you should be simply this.
  5. It's an error to have price column into your Ticket_Details table and ticket table, but it's may be a choice... The price can may be change into ticket table and not Ticket_Details table in same time (its a context question).

I propose this code :

CREATE PROCEDURE SeatPricing (IN seat_num varchar(2),IN ticketid varchar(10))
BEGIN 
DECLARE VALUETOSET decimal(5, 2);

IF seat_num LIKE 'A_' THEN
    SET VALUETOSET= 500.00 ;
ELSE
    SET VALUETOSET= 300.00 ;
END IF ;

UPDATE Ticket_Details SET seat_price = VALUETOSET and ticket_id = ticketid;

UPDATE Ticket SET seat_price = VALUETOSET and ticket_id = ticketid;

END

ERROR MESSAGE: SQL0104N An unexpected token "END@" was found following "_Details)". Expected tokens may include: " END IF".

Always refer the syntax for creating procedure . You need to end your procedure by ONLY END with optional <procedure-name> .

But, you have used END@ at the end, which should be either END or END SeatPricing .

END - A mandatory keyword that ends the block. You can optionally specify the name of the procedure .

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