# oracle-test **Repository Path**: he-donghua/oracle-test ## Basic Information - **Project Name**: oracle-test - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-11 - **Last Updated**: 2026-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # oracle-test `oracle-test` 是一个用于调试 Oracle 12.2.0 SQL 和脚本的 Spring Boot 项目。项目提供 RESTful 风格接口,并集成 Swagger UI,方便通过浏览器发起调试请求。 ## 功能特性 - 支持 Oracle Database 12.2.0 兼容实例 - 使用 Oracle JDBC 驱动 `ojdbc8:12.2.0.1` - 提供 RESTful API 调试 SQL、DML、DDL 和脚本 - 支持 Swagger UI 在线接口文档 - 支持命名参数 SQL,例如 `:id`、`:name` - 支持通过环境变量切换数据库连接配置 ## 环境要求 - JDK 17 或更高版本 - Maven 3.6.3 或更高版本 - Oracle Database 12.2.0 或兼容版本 ## 数据库配置 默认配置文件位置: ```text src/main/resources/application.yml ``` 默认连接配置如下: ```yaml spring: datasource: driver-class-name: oracle.jdbc.OracleDriver url: ${ORACLE_URL:jdbc:oracle:thin:@localhost:1521/ORCLPDB1} username: ${ORACLE_USERNAME:system} password: ${ORACLE_PASSWORD:oracle} ``` 推荐使用环境变量覆盖默认配置: ```bash export ORACLE_URL='jdbc:oracle:thin:@localhost:1521/ORCLPDB1' export ORACLE_USERNAME='system' export ORACLE_PASSWORD='oracle' export ORACLE_TEST_MAX_ROWS='200' ``` 如果使用 SID 方式连接 Oracle,可以将连接地址改为: ```bash export ORACLE_URL='jdbc:oracle:thin:@localhost:1521:ORCL' ``` ## 启动项目 进入项目目录: ```bash cd oracle-test ``` 启动 Spring Boot 服务: ```bash mvn spring-boot:run ``` 服务默认端口为 `8080`。 ## Swagger 文档 启动项目后,访问 Swagger UI: ```text http://localhost:8080/swagger-ui.html ``` OpenAPI JSON 地址: ```text http://localhost:8080/v3/api-docs ``` ## RESTful API 接口统一前缀: ```text /api/oracle ``` ### 检查数据库连接 ```http GET /api/oracle/health ``` 用于检查 Oracle 连接状态、数据库版本、驱动版本和当前用户。 ### 执行查询 SQL ```http POST /api/oracle/queries ``` 用于执行 `SELECT` 查询语句。 请求示例: ```json { "sql": "select * from user_tables where rownum <= :limit", "params": { "limit": 10 }, "maxRows": 10 } ``` ### 执行 SQL 命令 ```http POST /api/oracle/commands ``` 用于执行 `insert`、`update`、`delete`、DDL 语句或匿名 PL/SQL 块。 请求示例: ```json { "sql": "insert into demo_table (id, name) values (:id, :name)", "params": { "id": 1, "name": "hello" } } ``` ### 执行脚本 ```http POST /api/oracle/scripts ``` 用于执行以分号分隔的 Oracle 脚本。 请求示例: ```json { "script": "create table demo_table (id number primary key, name varchar2(50)); insert into demo_table values (1, 'hello')", "continueOnError": false } ``` 参数说明: - `script`:需要执行的 SQL 脚本内容。 - `continueOnError`:某条语句执行失败后是否继续执行后续语句。 ## 常用调试流程 1. 修改数据库连接环境变量。 2. 启动项目。 3. 打开 Swagger UI。 4. 调用 `GET /api/oracle/health` 确认数据库连接正常。 5. 使用 `/queries`、`/commands` 或 `/scripts` 调试 SQL 和脚本。 ## 注意事项 该项目暴露了 SQL 执行接口,仅适合本地开发和受控环境调试使用。不要在公网或不可信网络中部署该项目,除非已经增加认证、授权、审计和访问控制。