让我们首先创建一个新表并继续理解概念
create table StoredProcedureInsertDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserAge int -> );
这是创建存储过程以将数据插入表中的查询
DELIMITER // create procedure procedure_InsertIntoTable(IN FirstName VARCHAR(100),IN Age INT) -> BEGIN -> insert into StoredProcedureInsertDemo(UserName,UserAge) values (FirstName,Age); -> END -> // DELIMITER ;
借助CALL命令调用存储过程,如下所示
call procedure_InsertIntoTable('Larry',23);
再次检查表记录。
查询如下-
select *from StoredProcedureInsertDemo;
以下是输出
+--------+----------+---------+ | UserId | UserName | UserAge | +--------+----------+---------+ | 1 | Larry | 23 | +--------+----------+---------+ 1 row in set (0.00 sec)