SQL Text by ID (sqltext.sql)
What This Script Does
Section titled “What This Script Does”Retrieves and displays the complete SQL statement text for a specific SQL_ID from the shared SQL area.
The Script
Section titled “The Script”rem vsortusage.sqlremset pagesize 140set linesize 80remttitle 'SQL Text by SQLID'remcol sql_text format a80 word_wrappedremselect sql_textfrom v$sqltextwhere sql_id = '&sqlid'order by piece/
set pagesize 50
-- Basic usage@sqltext.sql
Parameters
Section titled “Parameters”The script prompts for:
- &sqlid - **: The SQL_ID of the statement you want to view
Required Privileges
Section titled “Required Privileges”SELECT ANY DICTIONARY-- OR --```## Sample Output
SQL Text by SQLID
SQL_TEXT
Section titled “SQL_TEXT”SELECT e.employee_id, e.first_name, e.last_name, d.department_name FROM employ ees e JOIN departments d ON e.department_id = d.department_id WHERE e.hire_dat e > TO_DATE(‘2020-01-01’, ‘YYYY-MM-DD’) ORDER BY e.hire_date DESC
## Key Output Information
- **SQL_TEXT**: The complete SQL statement text, formatted with word wrapping for readability- Text is assembled in order from multiple pieces if the SQL is longer than 1000 characters
## Common Use Cases
**Performance Analysis**```sql-- View the actual SQL text when investigating slow queries@sqltext.sql-- Enter: [appropriate values]
Query Identification
-- Understand what a SQL_ID represents when found in AWR or ASH reports@sqltext.sql