我想从select语句中检索一个值,并在insert语句中使用它。但是,这两个操作都要在单个存储过程中完成。我正在尝试下面的东西。
CREATE PROCEDURE Illness_sp (IN DoctorNameIn varchar(255), IN IllnessNameIn varchar(255), IN IllnessSevIn int(10))
BEGIN
select doctorId from doctor where DoctorName=DoctorNameIn;
INSERT INTO Illness(IllnessName, IllnessSeverity, PreferredDoctorId) Values(IllnessNameIn, IllnessSevIn, doctorId);
END
我在这个存储过程中有两个语句:
从doctorId
语句中检索SELECT
;和
希望INSERT
将其插入第二个声明中的另一个表格。
答案 0 :(得分:0)
INSERT INTO `Illness`(IllnessName, IllnessSeverity, PreferredDoctorId)
SELECT IllnessName, IllnessSeverity, PreferredDoctorId
FROM `SomeTable`
WHERE ...