Oracle定时任务和存储过程

--1.声明定时任务
DECLARE
   job NUMBER;
BIGIN
dbms_job.sumit(
   job,           --任务ID,系统定义的
   'test_prcedure(19)',--调用存储过程?
   to_date('20240305 02:00','yyyymmdd hh24:mi') --任务开始时间
   'sysdate+1/(24*60)'   --任务执行周期 [每分钟执行一次]
);
COMMIT;
END;
--2.定义存储过程
CREATE OR REPLACE procedure test_prcedure(in_num number) IS
BEGIN
	dbms_output_put_line(in_num) --打印输出19,当然它实际应该是一些列增删改操作
END

 分支语句

循环语句 

 游标操作(类比集合)

java调用存储过程

package com.dj.springtest.demo;
import java.sql.*;
/**
 * User: ldj
 * Date: 2024/3/4
 * Time: 23:48
 * Description: java调用存储过程
 */
public class CallProcedureDemo {
    public static void main(String[] args) throws Exception {
        Connection connection = null;
        CallableStatement callableStatement = null;
        try {
            //加载驱动
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //通过驱动管理器获取连接对象
            String url = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "root";
            String password = "123456";
            connection = DriverManager.getConnection(url, username, password);
            //拼接sql脚本,调用存储过程(test_procedure)有1个入参,1个出参
            String sql = "{call test_procedure(?,?)}";
            callableStatement = connection.prepareCall(sql);
            //设置入参和出参
            callableStatement.setInt(1, 18);
            callableStatement.registerOutParameter(2, JDBCType.DOUBLE);
            //执行sql
            callableStatement.execute();
            //获取结果
            System.out.println(callableStatement.getDouble(2));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭连接
            if (callableStatement != null) {
                callableStatement.close();
            }
            if (connection != null) {
                connection.close();
            }
        }
    }
}