Db2 xmlcast specification - db2

Select xmlcast('<case_id>123</case_id><checknumb>2345</checknumb>' as XML)
This query returns
<case_id;gt;123</case_id
<checknumb>2345</checknumb
How to get
<case_id>123</case_id<checknumb>2345</checknumb>
Why its coming like this when casting into xml.

Your code is trying to cast a string literal '<case_id>123</case_id><checknumb>2345</checknumb>' as an XML string, not an XML document. XML strings cannot contain angle brackets inside them, because these symbols have special meaning for XML parsers, so the angle brackets are converted to entities.
If what you really want is to convert your literal '<case_id>123</case_id><checknumb>2345</checknumb>' to an XML document, you need to make it a valid XML document first (by adding the root element) and then use XMLPARSE(DOCUMENT '<root><case_id>123</case_id><checknumb>2345</checknumb></root>') instead.

If you need to produce an XML sequence, then you should use XMLCONCAT scalar function, and not try to cast a string constant to the XML type.
VALUES XMLCONCAT(XMLELEMENT(NAME "case_id", 123), XMLELEMENT(NAME "checknumb", 2345));
If you need to produce an XML document, then you should use the following:
VALUES XMLELEMENT(NAME "doc", XMLCONCAT(XMLELEMENT(NAME "case_id", 123), XMLELEMENT(NAME "checknumb", 2345)));

Related

Data Factory activity to convert in proper json

I am running my ADF pipeline with Dataflow and I am getting the output as json as something like this
{"key1":"value1","key2":"[vaq:233,popo:basic5542]"}
However, my actual requirement is to have something like this.
{"key1":"value1","key2":["vaq:233","popo:basic5542"]}
Check the placement of double inverted commas for key "key2".In my Data factory pipeline I am using Derived column action in Dataflow and for key2 I am doing concat ("[",Data1,",popo:basic5542]" ) and Data1 has value vaq:233.
How can I adjust the double inverted comma here?
You could you use the below expression and check whether this meets your requirement.
array(Data1,"popo:basic5542")
Instead of the concat function.
Output :
["pea:P1013","popo:basic5542"]
Considering popo:basic5542 is a static value, you can try as below expression.
concat("[","\"",Data1,"\"",",","\"","popo:basic5542","\"","]")
Or if you are getting popo and basic5542 dynamically, you can try as below.
concat("[","\"",Data1,"\"",",","\"",popo,":",basic5542,"\"","]")
Example:

How to extract the value from a json object in Azure Data Factory

I have my ADF pipeline, Where my final output from set variable activity is something like this {name:test, value:1234},
The input coming to this variable is
{
"variableName": "test",
"value": "test:1234"
}
The expression provided in Set variable Item column is #item().ColumnName. And the ColumnName in my JSon file is something like this "ColumnName":"test:1234"
How can I change it so that I get only 1234. I am only interested in the value coming here.
It looks like you need to split the value by colon which you can do using Azure Data Factory (ADF) expressions and functions: the split function, which splits a string into an array and the last function to get the last item from the array. This works quite neatly in this case:
#last(split(variables('varWorking'), ':'))
Sample results:
Change the variable name to suit your case. You can also use string methods like lastIndexOf to locate the colon, and grab the rest of the string from there. A sample expression would be something like this:
#substring(variables('varWorking'),add(indexof(variables('varWorking'), ':'),1),4)
It's a bit more complicated but may work for you, depending on the requirement.
It seems like you are using it inside of an iterator since you got item but however, I tried with a simple json lookup value
#last(split(activity('Lookup').output.value[0].ColumnName,':'))

azure data flow convert string json array to json array

I'm using azure data flow, and I want to pass a json array inside an at() function like this :
the error is :
At function takes an array or a map for the first parameter.
urls value is :
[{"url":"http://url1.com"},{"url":"http://url2.com"},{"url":"http://url3.com"},{"url":"http://url4.com"}]
why it consider urls value as a string ?
You can convert to an array using the Derived column transformation.
In a Derived Column, first replace square brackets with empty/blank and with split function, split the string based on the delimiter comma (,).
Derived Column preview:
Now you can use this array in the at() function in your expression.

AEM Query Builder property value is not empty

How can I get results in the query builder snippet below that the industries page property has a value? (i.e., its value is not an empty string)
path=/content/apps
type=nt:unstructured
property=industries
property.value=
You can use the like operation for using the [jcr:like xpath function][1]
path=/content/apps
type=nt:unstructured
property=industries
property.value=%_%
property.operation=like
The corresponding xpath query would be
/jcr:root/content/apps//element(*, nt:unstructured)
[
(jcr:like(#industries, '%_%'))
]
Quoting the docs
As in SQL, the character ‘%’ represents any string of zero or more characters, and the character ‘_’ (underscore) represents any single character.
Please note that if the value contains a space alone, it is still considered valid as this function doesn't trim and then validate. Only if there is no value then it is excluded from the results.

DB2 how do I replace a double quote returned by an XML element

I am able to successfully retrieve the value of XML element using the following SQL
*SELECT XMLQUERY('$item/*:ItemSpec/*:AdditionalDescription/*:ABCDescription/text()' PASSING productval.value_xml as "item") AS H_DESCRIPTION FROM USER1.XMETA*
This returns a value that has double quotes (") in it. How do I replace it with a different value in the same select query. I tried something like this but it didn't work
Select REPLACE(XMLQUERY('$item/*:ItemSpec/*:AdditionalDescription/*:ABCDescription/text()' PASSING productval.value_xml as "item"),'"','QUOT') AS H_DESCRIPTION
The error is No authorized routine named "REPLACE" of type "FUNCTION" having compatible arguments was found...SQLCODE=-440,SQLSTATE==-42884.
XMLQUERY returnes an XML type, try casting it to varchar before applying REPLACE on it:
REPLACE(XMLCAST(XMLQUERY('$item/*:ItemSpec/*:Addition ...) AS VARCHAR(...)), '"','QUOT') AS ..