CREATE TRIGGER via JDBC ?
513061May 15 2006 — edited May 16 2006Hi,
I'm facing a problem with the CREATE TRIGGER DDL statement when executing it via JDBC. Assume for instance the following basic auto-increment trigger:
CREATE SEQUENCE seq_test_avalue;
CREATE TABLE test
(
pk INTEGER NOT NULL,
avalue INTEGER NOT NULL ,
PRIMARY KEY (pk)
);
CREATE OR REPLACE TRIGGER trg_test_avalue
BEFORE INSERT ON test
FOR EACH ROW
WHEN (NEW.avalue IS NULL)
BEGIN
SELECT seq_test_avalue.nextval INTO :NEW.avalue FROM DUAL;
END;
INSERT INTO test (pk) VALUES (1);
When I execute this via SQLDeveloper against a normal 10g database, everything works just fine.
But when I use JDBC with the 10g JDBC driver - e.g. in a programm via executeUpdate, or via SQuirrel SQL (http://squirrel-sql.sourceforge.net/) - then I get an ORA-00900 right after the first semicolon in the CREATE TRIGGER statement (the one before the END).
Interestingly, when I replace the WHEN clause with the corresponding IF statement in the trigger body:
CREATE OR REPLACE TRIGGER trg_test_avalue
BEFORE INSERT ON test
FOR EACH ROW
BEGIN
IF (:NEW.avalue IS NULL) THEN
SELECT seq_test_avalue.nextval INTO :NEW.avalue FROM DUAL;
END IF;
END;
then the error happens again after the first semicolon which is this time right before the END IF.
This leads me to the assumption that the JDBC driver does not recognize that the body of the CREATE TRIGGER is PL/SQL and thus assumes that this construct actually represents two SQL statements.
My question is, is there a way to create the trigger via JDBC ? E.g. can I change the delimiter for the PL/SQL part, or is there a way to escape the PL/SQL part or at least the semicolons in it ?