Oracle PL/SQL获取Undo值转XML遇PLS-00428错误求助
Fixing ORA-06550/PLS-00428 Error in Your PL/SQL XML Generation Script
Let's break down what's causing your error and fix it, plus add the timestamp tracking you need for monitoring undo value changes.
Why You're Getting the Error
The PLS-00428: an INTO clause is expected in this SELECT statement error pops up because in a PL/SQL block, every SELECT statement must store its results in variables using an INTO clause. On top of that, you incorrectly placed into d and into g inside your subqueries—those don't belong there; subqueries used as data sources in the FROM clause never use INTO.
Corrected Script with Timestamp Tracking
Here's the fixed version that generates the required XML, including the current undo value, recommended undo value, and a query timestamp:
set heading off set serveroutput on DECLARE l_xmltype XMLTYPE; BEGIN -- Generate XML with undo metrics and tracking timestamp SELECT dbms_xmlgen.getxml( 'SELECT SUBSTR(e.value,1,25) "curundo", ROUND(d.undo_size / (to_number(f.value) * g.undo_block_per_sec)) "recundo", SYSTIMESTAMP "query_timestamp" -- Add precise timestamp for change tracking FROM (SELECT SUM(a.bytes) undo_size FROM v$datafile a, v$tablespace b, dba_tablespaces c WHERE c.contents = ''UNDO'' AND c.status = ''ONLINE'' AND b.name = c.tablespace_name AND a.ts# = b.ts#) d, v$parameter e, v$parameter f, (SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) undo_block_per_sec FROM v$undostat) g WHERE e.name = ''undo_retention'' AND f.name = ''db_block_size''' ) INTO l_xmltype -- Store XML result in variable (required for PL/SQL blocks) FROM dual; -- Output the XML string for PowerShell to parse DBMS_OUTPUT.PUT_LINE(l_xmltype.getClobVal()); END; /
Key Changes Made:
- Added
INTO l_xmltypeto the mainSELECTstatement: This is mandatory in PL/SQL to capture the result of your query (the generated XML). - Removed invalid
into dandinto gfrom subqueries: Those subqueries act as temporary datasets in theFROMclause, so they don't need anINTOclause. - Added
SYSTIMESTAMP "query_timestamp": This adds a high-precision timestamp to your output, letting you track how the recommended undo value changes over time. - Enabled
serveroutput on: Ensures the XML output is printed to your terminal/SQL client so PowerShell can capture it.
How to Run:
- First execute
set serveroutput on(if it's not already enabled) to view the XML output. - Run the full script. The generated XML will be printed, which you can pipe directly into PowerShell for parsing.
内容的提问来源于stack exchange,提问作者90mph
相关产品推荐
相关产品推荐

