# dbExSQL **Repository Path**: rea-leaf/db-ex-sql ## Basic Information - **Project Name**: dbExSQL - **Description**: oralce 脚本导出标准sql工具 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-06-24 - **Last Updated**: 2026-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Ora2SQL Ora2SQL 是一个带图形界面的 Oracle SQL 导出工具,用于按模式(Schema)导出 Oracle 数据库对象和少量表数据。 ## 功能 - 支持 Oracle 19c/12c thin mode 连接。 - 支持 Oracle 11g thick mode 连接,程序内置 `instant_client`。 - 支持连接后选择可访问的模式。 - 支持选择导出对象: - 表结构 - 表和字段注释 - 索引(自动跳过主键索引) - 视图 - 序列 - 函数 - 存储过程 - 表数据 - 支持按表筛选导出。 - 支持数据导出行数限制和 WHERE 条件。 - 支持 BLOB/CLOB/NCLOB 数据导出。 - 导出完成后可选择直接打开输出目录。 ## 目录结构 ```text dbExSQL/ dist/ Ora2SQL.exe # 打包后的可执行程序 config.json # exe 使用的运行配置 ora2sql/ main.py # 源码入口 build_exe.ps1 # 打包脚本 config.json # 源码运行默认配置 requirements.txt # Python 依赖 instant_client/ # Oracle Instant Client gui/ # Tkinter 界面 exporters/ # 各类 SQL 导出器 tests/ # 单元测试 ``` ## 运行程序 直接运行: ```powershell .\dist\Ora2SQL.exe ``` 程序会读取同目录下的: ```text dist\config.json ``` ## 使用流程 1. 填写 Oracle 连接信息。 2. 选择 Oracle 版本。 3. 点击“测试连接”。 4. 连接成功后,点击或等待刷新模式列表。 5. 选择要导出的模式。 6. 按需勾选导出选项。 7. 点击“查询表”,选择需要导出的表;不选择表示全部。 8. 设置输出目录。 9. 点击“开始导出 SQL”。 10. 导出完成后,可选择打开输出目录。 ## WHERE 条件 WHERE 条件格式: ```text 表名=条件 ``` 多个表条件用英文分号分隔: ```text EMP=DEPTNO=10; DEPT=LOC='BJ' ``` 导出数据时,会对对应表追加条件。 ## 配置说明 `config.json` 示例: ```json { "oracle": { "host": "192.168.6.66", "port": 1521, "service_name": "PHXORCL", "user": "hisopt", "password": "hisopt", "oracle_version": "19c", "schema": "COREX_KETTLE" }, "export": { "output_dir": "./output", "table_structure": true, "comments": true, "indexes": true, "views": true, "sequences": true, "functions": true, "procedures": true, "selected_tables": [], "data": { "enabled": true, "max_rows_per_table": 100, "where_clauses": {} } } } ``` ## 源码运行 安装依赖: ```powershell cd .\ora2sql python -m pip install -r requirements.txt ``` 运行: ```powershell python .\main.py ``` 运行测试: ```powershell python -m pytest -q ``` ## 打包 使用 PowerShell 7 运行打包脚本: ```powershell & 'C:\Program Files (x86)\PowerShell\7\pwsh.exe' -File .\ora2sql\build_exe.ps1 ``` 脚本会: - 自动关闭正在运行的 `Ora2SQL.exe`。 - 使用 PyInstaller 打包。 - 收集 `cryptography`、`oracledb` 依赖。 - 打包 `config.json` 和 `instant_client`。 - 将 exe 复制到 `dist\Ora2SQL.exe`。 如需 console 版本方便看错误: ```powershell & 'C:\Program Files (x86)\PowerShell\7\pwsh.exe' -File .\ora2sql\build_exe.ps1 -Console ``` ## 常见问题 ### 11g 连接失败 请确认: - Oracle 版本选择为 `11g`。 - `ora2sql\instant_client` 目录存在,并包含 `oci.dll`。 - Instant Client 位数与 Python/程序位数一致。 ### thin mode 提示 cryptography 或 x509 错误 请重新打包,脚本已显式收集 `cryptography` 子模块。 ### ORA-00933 通常是当前 Oracle 版本不支持某些 SQL 语法。对于 11g,请选择 `11g` 版本,数据行数限制会使用 `ROWNUM`。 ### BLOB/CLOB 导出失败 当前版本已支持 LOB 对象读取;如果仍失败,请查看导出日志中的具体表名和字段。 ## 输出文件 导出结果按类型拆分: ```text tables.sql indexes.sql views.sql sequences.sql functions.sql procedures.sql data.sql ``` 主键已经包含在 `tables.sql` 的 `PRIMARY KEY` 中,`indexes.sql` 不再重复导出主键索引。