A lightweight command-line tool to connect to an Oracle database, run SQL queries (inline or from file), and export results to CSV — using Python and the oracledb driver.
- Connects to Oracle DB (thin mode, no Instant Client required)
- Run SQL from
.sqlfiles or inline strings - Export query results to CSV
- Safe, clean, and easy to extend or integrate into scripts and pipelines
- Test-covered and modular
- Python 3.7+
- Oracle database (local or remote)
- Python package:
oracledb
- Clone the repo
git clone https://github.com/crispusomollo/oracle-cli-tool.git
cd oracle-cli-tool- Create virtual environment
python3 -m venv oracledb-env
source oracledb-env/bin/activate- Install dependencies
pip install -r requirements.txt- Edit config.py to match your Oracle DB credentials:
DB_CONFIG = {
"user": "your_user",
"password": "your_password",
"dsn": "your_host:1521/your_service_name"
}python main.py --query sample_query(Reads sql/sample query.sql)
python main.py --sql "SELECT * FROM employees"💾 Export query to CSV
python main.py --query sample_query --out result.csvCSV is saved to output/result.csv
🧪 Run Tests
python3 -m unittest discover testsdocker pull crispusmomollo/oracle-cli
docker run --rm \
-v $(pwd)/sql:/app/sql \
-v $(pwd)/output:/app/output \
crispusmomollo/oracle-cli --query sample_queryoracle-cli-tool/
├── main.py # CLI entry point
├── db.py # DB functions
├── config.py # Connection details
├── sql/ # Folder for saved queries
│ └── sample_query.sql
├── output/ # CSV exports go here
├── requirements.txt
└── README.md- Place your queries inside sql/ as .sql files.
- Refer to them by name (without .sql) using --query.
- All CSVs are exported to the output/ folder.
Install dependencies manually if needed:
pip install oracledbMIT — free to use and modify.
-
Docker support
-
Insert from CSV
-
JSON output
-
GitHub Actions CI
Pull requests and issues welcome! Feel free to fork and enhance.