MySQL Forums
Forum List  »  General

Dynamic SQL with Dynamic xpath variable
Posted by: P Rike
Date: April 04, 2025 07:27AM

I have a loop that I am using to populate a variable with an xpath.

@xpath = concat('/record[',i,']/firstName');

I then have a variable I used to populate my sql statement.

@sql = 'select @value:=EXTRACTVALUE(xml,@xpath)';

then I use this statement to call the dynamic SQL.

PREPARE dynamic_statement1 FROM @valuesql;
EXECUTE dynamic_statement1;
DEALLOCATE PREPARE dynamic_statement1;

What is weird is it works some of the time and sometimes not and I can't find a pattern. I know my xpath is correct because if I just run this with the static xpath it returns a value.

SELECT @value:=EXTRACTVALUE(XML,'/record[1]/firstName');

Any ideas?

Options: ReplyQuote


Subject
Written By
Posted
Dynamic SQL with Dynamic xpath variable
April 04, 2025 07:27AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.