0

As part of a larger project trying to pull this data into Powershell, I am using a PL/SQL script to pull the undo values - current and recommended, from Oracle and output to an XML file that I can then parse with Powershell. I would also eventually like the recommended undo parameter to return with a timestamp that the query was run at to compare how it changes over a period of time.

At this point though, I am just working with trying to output as follows:

<currundo>903</currundo>
<recundo>14400</recundo>

When I run this pl/sql I am getting:

ERROR at line 5:
ORA-06550: line 5, column 5:
PLS-00428: an INTO clause is expected in this SELECT statement

Here is the code:

set heading off

DECLARE
    l_xmltype XMLTYPE;

BEGIN
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"
  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#
       ) into d,
       v$parameter e,
       v$parameter f,
       (
       SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
              undo_block_per_sec
         FROM v$undostat
       ) into g
WHERE e.name = ''undo_retention''
  AND f.name = ''db_block_size''') from dual;

END;
/

1 Answer 1

2

I fixed your "into" references and datatypes to yield this

SQL> DECLARE
  2      l_xmltype clob;
  3
  4  BEGIN
  5  select dbms_xmlgen.getxml('SELECT SUBSTR(e.value,1,25) "curundo",
  6        ROUND(d.undo_size / (to_number(f.value) * g.undo_block_per_sec)) "recundo"
  7    FROM (
  8         SELECT SUM(a.bytes) undo_size
  9            FROM v$datafile a,
 10                 v$tablespace b,
 11                 dba_tablespaces c
 12           WHERE c.contents = ''UNDO''
 13             AND c.status = ''ONLINE''
 14             AND b.name = c.tablespace_name
 15             AND a.ts# = b.ts#
 16         )  d,
 17         v$parameter e,
 18         v$parameter f,
 19         (
 20         SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
 21                undo_block_per_sec
 22           FROM v$undostat
 23         )  g
 24  WHERE e.name = ''undo_retention''
 25    AND f.name = ''db_block_size''')
 26    into l_xmltype from dual;
 27
 28  END;
 29  /

PL/SQL procedure successfully completed.

Of course that simply put the output into a variable. If you want it on screen, you can just do the select without PLSQL, eg

SQL> spool myfile.out
SQL> select dbms_xmlgen.getxml('SELECT SUBSTR(e.value,1,25) "curundo",
  2    ROUND(d.undo_size / (to_number(f.value) * g.undo_block_per_sec)) "recundo"
  3    FROM (
  4         SELECT SUM(a.bytes) undo_size
  5            FROM v$datafile a,
  6                 v$tablespace b,
  7                 dba_tablespaces c
  8           WHERE c.contents = ''UNDO''
  9             AND c.status = ''ONLINE''
 10             AND b.name = c.tablespace_name
 11             AND a.ts# = b.ts#
 12         )  d,
 13         v$parameter e,
 14         v$parameter f,
 15         (
 16         SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
 17                undo_block_per_sec
 18           FROM v$undostat
 19         )  g
 20  WHERE e.name = ''undo_retention''
 21    AND f.name = ''db_block_size''')
 22    from dual;

DBMS_XMLGEN.GETXML('SELECTSUBSTR(E.VALUE,1,25)"CURUNDO",ROUND(D.UNDO_SIZE/(TO_NU
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<ROWSET>
 <ROW>
  <curundo>900</curundo>
  <recundo>41668</recundo>
 </ROW>
</ROWSET>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I see now how that is working. I appreciate your assistance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.