我有 oracle 表之类的,
CREATE TABLE T_TEST(
INFO1 VARCHAR2(2000 CHAR),
INFO2 VARCHAR2(2000 CHAR),
INFO CLOB)
为了将数据插入此表,我有一个返回空 clob 的函数
function Insert_TEST(in_infotext1 in T_TEST.info1%type := null,
in_infotext2 in T_TEST.info2%type := null,)
return T_TEST.info%type
is
l_info T_TEST.info%type;
begin
insert into T_TEST
( INFO1,
INFO2,
info,)
values ( in_infotext1,
in_infotext2,
empty_clob())
returning info into l_info;
return l_info;
end;
要调用此函数,我使用以下 sql,
declare
myinfo clob;
begin
myinfo := Insert_TEST('Info1', 'Info2');
DBMS_LOB.OPEN(myinfo, DBMS_LOB.LOB_READWRITE);
DBMS_LOB.WRITE(myinfo,14,1,'My Information');
DBMS_LOB.CLOSE(myinfo);
COMMIT;
end;
这个 sql 在 SQL Developer 中完美运行,但是当我尝试使用 org.springframework.jdbc.core.JdbcTemplate 执行这个 sql 时,我的程序进入了无限循环。我的Java编码如下
OracleConnectionPoolDataSource dataSource = new OracleConnectionPoolDataSource();
dataSource.setURL("jdbc:oracle:thin:@localhost:1521:orcl");
dataSource.setUser("test");
dataSource.setPassword("test");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String query =
"declare "+
" myinfo clob; "+
"begin "+
" myinfo := Insert_TEST('Info1', 'Info2');"+
" DBMS_LOB.OPEN(myinfo, DBMS_LOB.LOB_READWRITE); "+
" DBMS_LOB.WRITE(myinfo,14,1,'My Information'); "+
" DBMS_LOB.CLOSE(myinfo); "+
" COMMIT; "+
"end;";
jdbcTemplate.execute(query);
谢谢