Board index » delphi » problem with creating a Trigger in Oracle database

problem with creating a Trigger in Oracle database

Hi,

I want to create the following table, where the field ID must be a
autoincrement field.

 TABLE R_ZEE (  ID           NUMBER(10)   ,
                             DESCRIPTION  VARCHAR2(25));

The following code must create the table, with sequence and trigger:

// create table
Query1.SQL.Clear;
Query1.SQL.Add('CREATE TABLE R_ZEE ( ID NUMBER(10), DESCRIPTION
VARCHAR2(25))');
Query1.ExecSQL;
// create sequence
Query1.SQL.Clear;
Query1.SQL.Add('CREATE SEQUENCE ZEEID_SEQ START WITH 1 INCREMENT BY 1
NOMAXVALUE MINVALUE 1 NOCYCLE CACHE 20 NOORDER');
Query1.ExecSQL;
// must create trigger
Query1.SQL.Clear;
Query1.SQL.Add('CREATE TRIGGER ZEEID_TRIG BEFORE INSERT');
Query1.SQL.Add('ON R_ZEE FOR EACH ROW');
Query1.SQL.Add('BEGIN');
Query1.SQL.Add('  SELECT ZEEID_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;');
Query1.SQL.Add('END;');
Query1.ExecSQL;

I get the following error:
'Project raised exception class  EDatabaseError with message 'Query1:
Field 'NEW.ID' is of an unknown type'.

I'am using Delphi 4 pack 2 and BDE 5.01 and Oracle 7.3.4

Ren Felten

 

Re:problem with creating a Trigger in Oracle database


Rene,
The problem is with the colon in :NEW_ID. Delphi interprets it as a reference
to a variable to be bound by the query.
I've read somewhere that the solution is to use a double colon i.e. ::NEW_ID.
Hope this helps.

groetjes,
Leo

Other Threads