Use SQLcl to connect to Oracle databases through a saved named connection and run generated `.sql` scripts directly with `sql -S`. Use when the user wants to query or modify an Oracle database, includes or can provide a SQLcl saved connection name in the prompt, expects Codex to extract that connection name when explicit, translate a natural-language request into a `.sql` file and execute it, or asks to dump data into an executable SQL export file.
Translate the user's database request into a .sql script, save it to disk, and run it with SQLcl against a saved named connection.
Do not guess the connection. Extract a SQLcl saved connection name from the user's prompt when it is explicit; otherwise ask for it.
Treat the connection as explicit when the prompt clearly names it, for example:
use connection hr-devrun this on fin_prodwith saved connection "orders-qa"using \analytics``Extraction rules:
connection, saved connection, using, with, on, or against, use it without asking a follow-up question.Use SQLcl's named connection form:
sql -S -name "<connection-name>" @/path/to/script.sql
If the prompt does not contain a single explicit connection name, stop and ask for it.
Write a concrete SQL or PL/SQL script from the user's request.
Default rules:
exit; as the final statement in every generated .sql file so SQLcl terminates after execution.set commands when they improve readable output.; and / where needed.delete, truncate, drop, alter, bulk update, grants, revokes), require explicit user intent.When the request is ambiguous, inspect the schema first with a read-only query rather than inventing table or column names.
Save the generated script as a .sql file before execution.
Before saving, ensure the file ends with exit;.
Preferred locations:
./tmp/sqlcl/<task-name>.sql/tmp/sqlcl/<task-name>.sql if the workspace should stay cleanCreate the parent directory if needed.
sql -SRun the saved file directly:
sql -S -name "<connection-name>" @/absolute/path/to/script.sql
After execution:
.sql file and explain the failing statement or connection problemIf the user asks to "dump data", do not stop at console output. Generate a SQL export file.
Preferred behavior:
.sql script that uses spool to write another .sql fileexit; to the end of the generator script and to the end of the exported .sql fileinsert statements for data dumps so the result can be replayed laterFor data dumps, the generated export file is the primary artifact.
Typical shape:
set echo off
set feedback off
set heading off
set pagesize 0
set trimspool on
set linesize 32767
spool /absolute/path/to/export.sql
select 'insert into employees(employee_id, first_name) values ('
|| employee_id
|| ', '''
|| replace(first_name, '''', '''''')
|| ''');'
from employees;
prompt exit;
spool off
exit;
Then execute the generator script with:
sql -S -name "<connection-name>" @/absolute/path/to/generate-dump.sql
After execution:
.sql file path.sql file as the result of the taskdbms_metadata.get_ddl(...)For query scripts, prefer readable output:
set echo off
set feedback on
set sqlformat ansiconsole
set pagesize 100
For DML or DDL scripts, include prompt lines so the execution log is easy to scan.
Use commit; only when the user explicitly requested a persistent change and autocommit should not be assumed.
User request:
"Use connection hr-dev and show the 20 most recent employees by hire date."
Script:
set echo off
set feedback on
set sqlformat ansiconsole
set pagesize 100
select employee_id, first_name, last_name, hire_date
from employees
order by hire_date desc
fetch first 20 rows only;
exit;
Execution:
sql -S -name "hr-dev" @/absolute/path/to/recent-employees.sql
User request: "Run this on orders-qa: dump rows from order_headers into a replayable SQL file."
Interpretation:
orders-qa as the saved connection name from the prompt.sql -S -name "orders-qa" ....@script.sql execution, and spool-based SQL exports.Spring Boot中的JPA/Hibernate模式,用于实体设计、关系处理、查询优化、事务管理、审计、索引、分页和连接池。