我尝试使用来自executeSqlScript
的内置函数AbstractTransactionalJUnit4SpringContextTests
使用以下外部SQL文件填充我的数据库。
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;
但是我得到以下错误。我不确定在我想用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文件中表达什么?
错误重现的原因是什么?
答案 0 :(得分:3)
您似乎正在尝试在脚本中使用PL / SQL的功能。
executeSqlScript(..)
中的AbstractTransactionalJUnit4SpringContextTests
方法在幕后内部委托给ScriptUtils.executeSqlScript(..)
,ScriptUtils
仅支持纯SQL脚本。
因此,您可能需要切换到简单的SQL语句,并找到一种不同的机制来从account__id
检索table1
的值。
另一个选项(我不尝试过)会将语句分隔符更改为";"
以外的其他内容(例如"end;"
),但是你不能这样做通过AbstractTransactionalJUnit4SpringContextTests.executeSqlScript
。相反,您需要调用ScriptUtils.executeSqlScript(..)
或(最好)使用ResourceDatabasePopulator
。