【发布时间】:2019-12-04 16:02:00
【问题描述】:
我有一个用 sql 文件编写的存储过程,我想使用 jdbc 模板通过 Spring Boot 代码执行该存储过程。存储过程是这样的:
CREATE OR REPLACE FUNCTION DELETE_REDUNDANT_RECORDS()
RETURNS void AS
$func$
DECLARE
interval_time BIGINT DEFAULT 0;
min_time BIGINT DEFAULT 0;
max_time BIGINT DEFAULT 0;
rec_old RECORD;
rec_new RECORD;
rec_start RECORD;
v_filename VARCHAR(250);
v_systemuid VARCHAR(50);
is_continous_record BOOLEAN default false;
cursor_file CURSOR FOR
select distinct filename,systemuid from ASP.MONITORING_BOOKMARK_ORIGINAL;
cursor_data CURSOR FOR
select * from ASP.MONITORING_BOOKMARK_ORIGINAL where filename = v_filename and systemuid=v_systemuid order by mindatetime, maxdatetime;
BEGIN
--open the file cursor to fetch the filename and systemuid
OPEN cursor_file;
-- logic for procedure
CLOSE cursor_file;
END;
$func$
LANGUAGE plpgsql;
我已经在我的 spring boot 项目的一个 sql 文件中添加了这个。我想创建一个调度程序来使用 spring jdbc 创建和执行这个存储过程。使用的数据库是 Postgres。有没有办法做到这一点。我有调用过程的参考资料,但我需要的是创建和执行过程。
【问题讨论】:
-
将代码放在一个字符串中,然后使用
Statement.execute(String)运行它 -
这也可以使用 jdbc 模板来完成吗?
标签: postgresql spring-boot stored-procedures spring-jdbc