CREATE PROCEDURE getNumbers
(
@dName VARCHAR(20),
@iNum INT OUTPUT,
@sNum INT OUTPUT
)
AS
BEGIN
@iNum=SELECT count(i.ID) FROM instructor WHERE dept_name=@dName
@sNum=SELECT count(s.ID) FROM student AS s WHERE dept_name=@dName
END
这是我第一次尝试制作存储过程。我一直在语法中遇到错误:@dName VARCHAR(20),
我已经查看了其他问题并尝试了他们的解决方案,但没有任何作用!
答案 0 :(得分:1)
请尝试以下表单:
CREATE PROCEDURE getNumbers
@dName VARCHAR(20),
@iNum INT OUTPUT,
@sNum INT OUTPUT
AS
BEGIN
答案 1 :(得分:1)
是MSSQL吗?如果是这样,您不需要使用括号,您应该使用以下语法来分配变量:
CREATE PROCEDURE getNumbers
@dName VARCHAR(20),
@iNum INT OUTPUT,
@sNum INT OUTPUT
AS
BEGIN
SELECT @iNum=count(i.ID) FROM instructor WHERE dept_name=@dName;
SELECT @sNum=count(s.ID) FROM student AS s WHERE dept_name=@dName;
END
如果你在MYSql
中这样做DELIMITER $$
CREATE PROCEDURE getNumbers(
IN dName VARCHAR(20),
OUT iNum INT,
OUT sNum INT)
BEGIN
SELECT count(i.ID) INTO iNum FROM instructor WHERE dept_name=dName;
SELECT count(s.ID) INTO sNum FROM student AS s WHERE dept_name=dName;
END$$
DELIMITER ;