我正在尝试在 IBExpert 中为 Firebird 2.5 数据库创建一个简单的存储过程。不过,我在使用发电机时遇到了麻烦。我想我已经创建了一个有效的生成器和触发器。但我不知道如何在我的执行语句中应用这些。
桌子:
ID BIGINT NOT NULL,
DATUM INTEGER,
KOSTENST INTEGER,
KUNDENNUMMER INTEGER,
DISPONENT CHAR(5),
KONTAKTART CHAR(2)
扳机:
CREATE OR ALTER trigger kontakte_erw_id_bi for kontakte_erw_id
active before insert position 0
AS
BEGIN
if (NEW.ID is NULL) then NEW.ID = GEN_ID(ID_KONTAKTE, 1);
END
发电机:
CREATE SEQUENCE ID_KONTAKTE;
ALTER SEQUENCE ID_KONTAKTE RESTART WITH 0;
过程语句(我认为问题出在此处?如何解决触发器以填充 ID 列?):
for execute statement('
SELECT
KONTAKTE.DATUM,
KUNDEN.KOSTENST,
KUNDEN.KUNDENNR,
KONTAKTE.DISPONENT,
KONTAKTE.KONTAKTART
FROM KONTAKTE
INNER JOIN KUNDEN ON KONTAKTE.KUNDENNR = KUNDEN.KUNDENNR
')
on external 'db'
as user 'xxx' password xxx
into :XDATUM, :XKOSTENST, :XKUNDENNUMMER, :XDISPONENT, :XKONTAKTART
do
begin
execute statement
('update or insert into KONTAKTE_ERW_ID (DATUM, KOSTENST, KUNDENNUMMER, DISPONENT, KONTAKTART)
values
(:DATUM, :KOSTENST, :KUNDENNUMMER, :DISPONENT, :KONTAKTART)')
(DATUM:= XDATUM, KOSTENST := XKOSTENST, KUNDENNUMMER := XKUNDENNUMMER, DISPONENT := XDISPONENT, KONTAKTART := XKONTAKTART)
on external 'db'
as user 'xxx' password xxx;
end
这是我尝试填充图表时遇到的错误:
336003099 : UPDATE OR INSERT field list does not match primary key of table KONTAKTE_ERW_ID
Statement : update or insert into KONTAKTE_ERW_ID (DATUM, KOSTENST, KUNDENNUMMER, DISPONENT, KONTAKTART)
values
(?, ?, ?, ?, ?)