本代码演示:
在mysql的存储过程中向表中添加数据的方法。
代码:
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; //删除mysql存储过程 drop PROCEDURE FIBONNACI_START; drop PROCEDURE FIBONNACI_GIVE;