我正在使用Firebird 2.x并且我已经创建了一个存储过程来插入记录(如果它不存在)并将其ID返回到变量中。
但是当我执行时,发现发生以下错误:
Dynamic SQL Error. SQL error code = -104. Unexpected end of command - line 2, column 76.
我的SP的完整源代码如下:
CREATE PROCEDURE INSERT_ADMIN_OFFICE
AS
DECLARE VARIABLE OFF_ID BIGINT;
DECLARE VARIABLE PER_ID BIGINT;
DECLARE VARIABLE EMP_ID BIGINT;
DECLARE VARIABLE AP_ID BIGINT;
BEGIN
IF (NOT EXISTS(SELECT * FROM OFFICE OFF WHERE OFF.DESCRIPTION LIKE '%Administrador%')) THEN
INSERT INTO OFFICE (DESCRIPTION) VALUES ('Administrador') RETURNING ID INTO :OFF_ID;
ELSE
SELECT OFF.ID FROM OFFICE OFF WHERE OFF.DESCRIPTION LIKE '%Administrador%' INTO :OFF_ID;
INSERT INTO PERSON (NAME, BIRTH_DATE, ADDRESS, DISTRICT, CITY, STATE) VALUES ('Intellitools Desenvolvimento de Software Ltda.', '01/01/2007', 'Rua Nunes Machado, 472 - Cj 503', 'Centro', 'Curitiba', 'PR') RETURNING ID INTO :PER_ID;
INSERT INTO USER_PASSPORT (PERSON_ID, USER_NAME, PWD, TYPE) VALUES (:PER_ID, 'intellitools', 123, 1);
INSERT INTO EMPLOYEE (OFFICE_ID, PERSON_ID) VALUES (:OFF_ID, :PER_ID) RETURNING ID INTO :EMP_ID;
INSERT INTO ACCESS_PROFILE (DESCRIPTION) VALUES ('Administrador Geral') RETURNING ID INTO :AP_ID;
INSERT INTO REL_EMPLOYEE_ACCESS_PROFILE (EMPLOYEE_ID, ACCESS_PROFILE_ID) VALUES (:EMP_ID, :AP_ID);
SUSPEND;
END
;
我注意到这个错误是因为INSERT上的INTO,但我找不到另一种方法。
感谢您的帮助!
答案 0 :(得分:1)
只需删除SUSPEND,您的proc就会像魅力一样执行。对于一次性操作,我建议执行BLOCK而不是创建存储过程。