Add data to a table with procedure
DELIMITER $$
CREATE TABLE FIBON
(NUMBER1 INTEGER NOT NULL PRIMARY KEY,
NUMBER2 INTEGER NOT NULL);
CREATE PROCEDURE FIBONNACI_START()
BEGIN
DELETE FROM FIBON;
INSERT INTO FIBON (NUMBER1, NUMBER2) VALUES (16, 27);
END
;
CREATE PROCEDURE FIBONNACI_GIVE
(INOUT NUMBER INTEGER)
BEGIN
DECLARE N1, N2 INTEGER;
SELECT NUMBER1, NUMBER2
INTO N1, N2
FROM FIBON;
SET NUMBER = N1 + N2;
IF NUMBER > 10000 THEN
SET NUMBER = NUMBER - 10000;
END IF;
SET N1 = N2;
SET N2 = NUMBER;
UPDATE FIBON
SET NUMBER1 = N1,
NUMBER2 = N2;
END$$
DELIMITER ;
CALL FIBONNACI_START()
;
CALL FIBONNACI_GIVE(@C)
;
SELECT @C
;
CALL FIBONNACI_GIVE(@C)
;
SELECT @C
;
CALL FIBONNACI_GIVE(@C)
;
SELECT @C;
drop table FIBON;
drop PROCEDURE FIBONNACI_START;
drop PROCEDURE FIBONNACI_GIVE;
Related examples in the same category