I am trying to select the count of tags in the XML(CLOB) column.
I tried with
select regexp_count(diagram, 'userTask id=', 1, 'c') as "User Tasks",
regexp_count(diagram, 'task id=', 1, 'c') as "Task"
from process_table
It works but, I need to get output faster than using regexp_count.
I tried with:
select count(xt.task),
count(xt.userTask)
from process_table process
cross join xmltable(
xmlnamespaces(default 'http://www.omg.org/spec/BPMN/20100524/MODEL'),
'//definitions/process' passing xmltype(process.diagram)
columns
task varchar2(20) path 'task',
userTask varchar2(60) path 'userTask'
) xt
But, I am getting an error ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
There are a few ways to do this. One is to use XMLTable to look for either child node, get the node names, and count how many times each appears:
Or you could use FLWOR expressions to get the count for both child node types at once:
but I'm not sure that would end up any faster than the first option.
Another option is to use separate XMLQuery XPath counts for each node to check:
db<>fiddle with a simple made-up XML CLOB that throws the error you see, and those three approaches (including converting the XMLQuery results to numbers).
I'm interested to see what other people come up with too.
This will error if a processed row has a null
diagram; but you can exclude those by just addingwhere diagram is not null.db<>fiddle