Baseline SQL Script (for Recent Performance Snapshot)

Here’s a sample SQL script to baseline a query by SQL_ID, returning key performance metrics that you can copy into Excel, store in a logging table, or track over time:

SELECT
    sql_id,
    plan_hash_value,
    TO_CHAR(SYSDATE, 'YYYY-MM-DD') AS baseline_date,
    ROUND(elapsed_time/1000000, 2) AS total_elapsed_sec,
    executions,
    ROUND((elapsed_time/1000000) / NULLIF(executions, 0), 2) AS avg_elapsed_sec,
    rows_processed,
    ROUND(rows_processed / NULLIF(executions, 0)) AS avg_rows,
    buffer_gets,
    ROUND(buffer_gets / NULLIF(executions, 0)) AS avg_buffer_gets,
    disk_reads,
    ROUND(disk_reads / NULLIF(executions, 0)) AS avg_disk_reads
FROM
    gv$sql
WHERE
    sql_id = '<your SQL_ID>'
ORDER BY
    last_active_time DESC
FETCH FIRST 1 ROWS ONLY;