복붙노트

[SPRING] executeSqlScript가 PL / SQL 용 Spring 블록과 함께 실패합니다.

SPRING

executeSqlScript가 PL / SQL 용 Spring 블록과 함께 실패합니다.

내장 함수를 사용하여 데이터베이스를 채우려 고 시도하는 중입니다. 다음 외부 SQL 파일을 사용하여 AbstractTransactionalJUnit4SpringContextTests의 executeSqlScript를 채 웁니다.

declare
   id number;
begin
   insert into table1 (field1) values ('V1') returning account__id  into id;
   insert into table2 (my_id, field2) VALUES (id, 'Value3');
end;

그러나 나는 다음과 같은 오류가 발생합니다. im은 executeSqlScript를 사용하여 실행하고자하는 SQL 파일에서 어떤 작업을 허용했는지 확신 할 수 없습니다.

org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [testdata.sql]: declare id number; nested exception is java.sql.SQLException: ORA-06550: line 1, column 17:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   := . ( @ % ; not null range default character
Caused by: java.sql.SQLException: ORA-06550: line 1, column 17:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   := . ( @ % ; not null range default character

그래서 내 질문은 : executeSqlScript에 대한 SQL 파일에서 무엇을 표현할 수 있습니까? 수신 오류의 원인은 무엇입니까?

해결법

  1. ==============================

    1.스크립트에서 PL / SQL의 기능을 사용하려고 시도하는 것 같습니다.

    스크립트에서 PL / SQL의 기능을 사용하려고 시도하는 것 같습니다.

    AbstractTransactionalJUnit4SpringContextTests의 executeSqlScript (..) 메소드는 내부적으로 ScriptUtils.executeSqlScript (..)에 내부적으로 위임하며 ScriptUtils는 순수한 SQL 스크립트 만 지원합니다.

    따라서 간단한 SQL 문으로 전환하고 table1에서 account__id 값을 가져 오는 다른 메커니즘을 찾아야 할 가능성이 높습니다.

    또 다른 옵션 (내가 시도하지 않은)은 명령문 분리 기호를 ";"이외의 것으로 변경하는 것입니다. (예 : "end;"),하지만 AbstractTransactionalJUnit4SpringContextTests.executeSqlScript를 통해이를 수행 할 수는 없습니다. 대신 ScriptUtils.executeSqlScript (..)를 호출하거나 ResourceDatabasePopulator를 (가급적이면) 사용해야합니다.

  2. from https://stackoverflow.com/questions/30753901/executesqlscript-fails-with-spring-for-pl-sql-block by cc-by-sa and MIT license