Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An INTO clause is expected in this SELECT statement error when fetching from XMLTABLE

I am trying to run a script that involves an xmltable and I am getting a

PLS-00428: an INTO clause is expected in this SELECT statement

How could I correct my script and get 2 rows from the xml?

Oracle 11g

DECLARE xml_char xmltype;
BEGIN
xml_char := xmltype.createXML('<xml><ROWSET><ROW UNIQUEID="All0" ALLOWCHG="0"/><ROW UNIQUEID="All1" ALLOWCHG="1"/></ROWSET></xml>');
select UNIQUEID, ALLOWCHG from xmltable ( '/xml/ROWSET/ROW' passing xml_char columns "UNIQUEID" varchar(30) path '@UNIQUEID', "ALLOWCHG" varchar(30) path '@ALLOWCHG' ) ;
END;
like image 683
evangelus Avatar asked Nov 24 '25 14:11

evangelus


1 Answers

In SQL, a select statement never contains an INTO clause.

In PL/SQL, a select statement requires an INTO clause unless it's in cursor. I modified your code to use a cursor:

DECLARE 
xml_char xmltype;

cursor c_cursor is
select UNIQUEID, ALLOWCHG 
from xmltable ( '/xml/ROWSET/ROW' 
                passing xml_char 
                columns 
                    "UNIQUEID" varchar(30) path '@UNIQUEID',
                    "ALLOWCHG" varchar(30) path '@ALLOWCHG'
              );

BEGIN

xml_char := xmltype.createXML('<xml><ROWSET><ROW UNIQUEID="All0" ALLOWCHG="0"/><ROW UNIQUEID="All1" ALLOWCHG="1"/></ROWSET></xml>');

for i in c_cursor loop  
  dbms_output.put_line('UNIQUEID: ' || i.uniqueid || ' ALLOWCHG: '|| i.allowchg);
end loop;

END;

Don't worry, we all make silly mistakes mate, I do despite years of experience.

like image 86
Ro Milton Avatar answered Nov 27 '25 10:11

Ro Milton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!