evangelus
evangelus

Reputation: 61

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;

Upvotes: 3

Views: 8835

Answers (1)

Ro Milton
Ro Milton

Reputation: 2526

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.

Upvotes: 12

Related Questions