views:

37

answers:

1

We use org.springframework.batch.test.DataSourceInitializer class in order to init DB on basis of .sql scripts.

Init was failed,after trigger had been added to .sql.

After debugging,the cause of error while was found here:

try {
scripts = StringUtils.delimitedListToStringArray(stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";");
}

This error happened,because delimiter is ";" symbol,so trigger was splittet into several parts on basis of ";" and treated uncorrectly.

Can you advise me more advanced data source initializer,that will understand triggers correctly?

Thank you.

+1  A: 

The CREATE TRIGGER statement is a PL/SQL block, and PL/SQL blocks must be terminated with a single / as the first character of a row.
This should work:

CREATE OR REPLACE TRIGGER "ACCOUNT_BIU" 
  BEFORE INSERT OR UPDATE ON ACCOUNT 
  REFERENCING OLD AS OLD NEW AS NEW 
  FOR EACH ROW 
BEGIN 
  IF (:NEW.ESKONTOTYPE_ID   IS NULL) THEN 
    IF (:NEW.KONTOTYPE_ID    ='NP') THEN 
      :NEW.ESKONTOTYPE_ID   := 311; 
    ELSIF (:NEW.KONTOTYPE_ID ='MT') THEN 
      :NEW.ESKONTOTYPE_ID   := 320; 
    ELSIF (:NEW.KONTOTYPE_ID ='NL') THEN 
      :NEW.ESKONTOTYPE_ID   := 330; 
    END IF; 
  END IF; 
  :NEW.ENDRETBRUKER := SUBSTR(USER,1,7); 
  :NEW.ENDRETDATO   := SYSDATE; 
END; 
/

ALTER TRIGGER "ACCOUNT_BIU" ENABLE; 
Adam Musch
hello, Adam ,i tried with '/', got the same error
sergionni
The delimiter needs to be the '/', not a ';' - Oracle can use ; as delimiters for SQL statements, but not PL/SQL blocks.
Adam Musch