Oracle定时任务和存储过程

javascript 复制代码
--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调用存储过程

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();
            }
        }
    }
}
相关推荐
setmoon2149 分钟前
使用Scikit-learn构建你的第一个机器学习模型
jvm·数据库·python
2401_8331977339 分钟前
为你的Python脚本添加图形界面(GUI)
jvm·数据库·python
执笔画情ora1 小时前
oracle数据库优化-表碎片优化性能。
数据库·oracle
givemeacar1 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
skiy1 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
IvorySQL1 小时前
PostgreSQL 技术日报 (3月24日)|当 MVCC 成本被重新审视
数据库·postgresql·开源
2401_895521341 小时前
PostgreSQL_安装部署
数据库·postgresql
Hvitur1 小时前
软考架构师【第六章】数据库设计基础知识
数据库·oracle
养生技术人2 小时前
Oracle OCP认证考试题目详解082系列第5题
运维·数据库·sql·oracle·开闭原则
2401_879693872 小时前
使用Python进行图像识别:CNN卷积神经网络实战
jvm·数据库·python