XML : Query Using XMLEXISTS Incorrectly Has "If Any" Behavior (Oracle 11g)

I'm working on a project which involves querying the contents on an XML document. I've come up with a simplified test case (below) to try and understand how it works. The problem is that the haskey field is true for every record if even one record has that tag. How do I get it to return true/false based on the existence of that child node in each record individually?

  DECLARE    players xmltype := xmltype('   <Players>    <Player username="player1">      <HasKey></HasKey>    </Player>    <Player username="player2">      <HasKey></HasKey>    </Player>    <Player username="player3">    </Player>  </Players>');  BEGIN    FOR c IN    (SELECT username,      (      CASE        WHEN xmlexists('$p/Players/Player/HasKey' passing players AS "p")        THEN 'TRUE'        ELSE 'FALSE'      END) haskey    FROM xmltable('/Players/Player' passing Players columns username VARCHAR2(30) path '@username' ) "p"    )    LOOP      dbms_output.put_line(c.username ||','|| c.haskey);    END LOOP;  END;    

No comments:

Post a Comment