我可以创建获取参数的存储过程并在insert statment中运行select语句吗?
我有2个问题: 1)如何获取商店程序的参数? 2)我可以像这样在插入语句中运行select statment吗?
DELIMITER $$
CREATE PROCEDURE `insertGuide` @m_name varchar(45) ,@m_last varchar(45) ,@addres varchar(45) ,@mphone int
BEGIN
INSERT INTO `guides` (`id`, `name`, `lastName`, `address`, `phone`)
VALUES (select max(id)+1 from seq,@m_name,@m_last,@addres,@mphone);
END
答案 0 :(得分:0)
我不明白第一个问题,但关于 INSERT 语句,这应该可行
INSERT INTO `guides` (`id`, `name`, `lastName`, `address`, `phone`)
select max(id)+1, @m_name, @m_last, @addres, @mphone
from seq;
答案 1 :(得分:0)
尝试这样:
DELIMITER $$
DROP PROCEDURE IF EXISTS insertGuide;
CREATE PROCEDURE insertGuide (id int, name varchar(45) ,last varchar(45) ,addres varchar(45) ,phone int(12))
BEGIN
INSERT INTO `guides` (`id`, `name`, `lastName`, `address`, `phone`)
VALUES (id, name, last, addres, phone);
END
您可以在插入中运行select查询,如:
INSERT INTO `guides` (`id`, `name`, `lastName`, `address`, `phone`)
SELECT MAX(id)+1, @m_name, @m_last, @addres, @mphone
FROM seq;