I am getting an error complaining about the OUT Parameter ID as an Undefined name when I try to set its value at the end of the procedure. Commenting it out the procedure executes fine. What am I doing wrong?
CREATE PROCEDURE P3.CUST_CRT(IN NAME VARCHAR(15),
IN GENDER CHAR(1),
IN AGE INTEGER,
IN PIN INTEGER,
OUT ID INTEGER)
LANGUAGE SQL
P1: BEGIN
--Check if Customer NAME is NULL.
IF NAME IS NULL THEN
SIGNAL SQLSTATE VALUE '20010'
SET MESSAGE_TEXT = 'No NAME.';
END IF;
--Check if Customer NAME is an empty string.
IF NAME = '' THEN
SIGNAL SQLSTATE VALUE '20020'
SET MESSAGE_TEXT = 'NAME cannot be an empty string.';
END IF;
--Check if Customer GENDER falls in either of the two acceptable categories.
IF GENDER NOT IN ('M','F') THEN
SIGNAL SQLSTATE VALUE '20030'
SET MESSAGE_TEXT = 'GENDER can either be M or F';
END IF;
--Check if Customer AGE is not null.
IF AGE IS NULL THEN
SIGNAL SQLSTATE VALUE '20040'
SET MESSAGE_TEXT = 'AGE cannot be NULL';
END IF;
--Check that AGE is not negative.
IF AGE < 0 THEN
SIGNAL SQLSTATE VALUE '20060'
SET MESSAGE_TEXT = 'AGE cannot be negative.';
END IF;
--Check that the Customer is an adult.
IF AGE < 18 THEN
SIGNAL SQLSTATE VALUE '20070'
SET MESSAGE_TEXT = 'You have to be over 18 years to have an account.';
END IF;
--Check that PIN is not null.
IF PIN IS NULL THEN
SIGNAL SQLSTATE VALUE '20080'
SET MESSAGE_TEXT = 'PIN cannot be empty.';
END IF;
--Pin cannot be less than zero.
IF PIN < 0 THEN
SIGNAL SQLSTATE VALUE '20090'
SET MESSAGE_TEXT = 'PIN cannot be less than 0.';
END IF;
INSERT INTO P3.CUSTOMER(Name, Gender, Age, Pin) VALUES(NAME, GENDER, AGE, P3.ENCRYPT(PIN));
SET ID = ID.CURRVAL;
END P1 @