This function prepares and executes the given SQL string, which should be a query expression with the FOR XML clause at the end of the last term. The query is passed the parameters from the params vector, which should have one element for each ? in the query text, values assigned from left to right. Consider the query: select a, b from table where a = ? and b = ?; then the params vector could reasonably be: vector(1, 'myfilter').
The result set is converted to XML and appended to the string_output. If the string_output is omitted and the function executes in the context of a VSP page, the output is sent to the stream going to the user agent.
If you omit the third parameter, this function will output to the context of the calling VSP page.
The procedure below takes an SQL string, evaluates it - converting to XML - and produces a result set where the XML text is returned as a varchar column. Parameters are not passed in this example for the sake of simplicity.
create procedure xmla (in q varchar) { declare st any; st := string_output (); xml_auto (q, vector (), st); result_names (q); result (string_output_string (st)); }