use*_*545 5 sql spring spring-test oracle11g
我尝试使用以下外部 SQL 文件executeSqlScript
使用内置函数填充我的数据库。AbstractTransactionalJUnit4SpringContextTests
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;
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误。我不确定我允许在 SQL 文件中执行什么操作,我想使用executeSqlScript
.
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
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:我可以在 SQL 文件中表达什么executeSqlScript
?我收到错误的原因是什么?
您似乎正在尝试在脚本中使用 PL/SQL 的功能。
executeSqlScript(..)
内部方法委托AbstractTransactionalJUnit4SpringContextTests
给ScriptUtils.executeSqlScript(..)
幕后,并且ScriptUtils
仅支持纯SQL脚本。
account__id
因此,您可能需要切换到简单的 SQL 语句并找到一种不同的机制来检索from的值table1
。
另一个选择(我没有尝试过)是将语句分隔符更改为除";"
(例如"end;"
)之外的其他内容,但您不能通过 来做到这一点AbstractTransactionalJUnit4SpringContextTests.executeSqlScript
。相反,您需要调用ScriptUtils.executeSqlScript(..)
或(也许最好)使用ResourceDatabasePopulator
.