の実行に失敗しました私は、MySQLでストアドプロシージャを作成しよう:は、SQLスクリプトステートメント(MySQLでのストアドプロシージャ)
create PROCEDURE sp_attachAuthorToBook(
IN _bookId INT,
IN _authorName VARCHAR(20)
)
BEGIN
declare _authorId int
select _authorId = id from Authors where name = _authorName
IF (_authorId is null) THEN
INSERT INTO Authors (name)
VALUES (_authorName)
SELECT _authorId = SCOPE_IDENTITY()
END IF
insert into Books_Authors (bookID, authorID)
values (_bookId, _authorId)
END;
しかし、私はエラーを取得:スクリプトがあまりにもあるよう
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select _authorId = id from Authors where name = _authorName IF (_authorId is nul' at line 1
らしいです実行される大きな。付近の線がちょうど壊れています。IF (_authorId is null) THEN
- IF (_authorId is nul
、このようにしてみてください。私はあなたがそのデータベースを使用している場合は、MySQLで少し調べることをお勧めします。 –
@ Gordon Linoff、私はSQLサーバーコードを使用しているように見えますか? – Ddd
。 。 'scope_identity()'はSQL Server(T-SQL)固有のものです。 –