on 2023 Feb 13 2:10 AM
Is there a way to convert a row type in XML format?
create or replace variable obj_User row(Id integer,Firstname varchar(16),Lastname varchar(64)); select row('1','Frank', 'Vestjens') into obj_User; select Obj_User "Users" for json rawIs working fine. However I would like to have something similar for XML. But select obj_User "Users" for xml raw does not work.
Any ideas?
Request clarification before answering.
I don't think there is a generic way to do so, as a row data type is simply not allowed as return value of an outer select statement.
select obj_User
returns the expected SQLCODE -1599 "Invalid use of collection type". (IMHO, it's somewhat surprising that FOR JSON does work here...)
So I guess you would need to decompose the row data type in its individual members, such as
select obj_User.Id, obj_User.Firstname, obj_User.Lastname for xml auto, elements -- returns <dummy><id>1</id><firstname>Frank</firstname><lastname>Vestjens</lastname></dummy>You might need the cumbersome FOR XML EXPLICIT syntax to achieve a particular XML format.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The reason I use row objects is for json generation in the database. the row data together with array(0 can define a proper layout of the json being generated. By defining that in a domain even makes it better to read.
User | Count |
---|---|
52 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.