So I have a need to be able to take a ROWTYPE argument and serialize it to a string. I know that there is a DBMS package to serialize to XML but I want to instead simply serialize it (if possible) to a name/value pair (e.g., colname1=colval1,colname2=colval2,...).
So I have created a very simple function where I'd basically pass in a row and this method would be able to parse that and serialize it.
CREATE OR REPLACE FUNCTION "A1CLIENT01"."SERIALIZE_TP"(AMyTabRec MyTable%ROWTYPE) RETURN VARCHAR2
is
begin
... work some magic here...
return theMagicString;
end;
What I thought would be easy is not possible (it seems), but I was thinking something like the following:
CURSOR MyTabCur IS
SELECT COLUMN_NAME INTO lCurrColumn
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = 'MyTable';
FOR a_mytab_rec IN MyTabCur
LOOP
theMagicString := theMagicString || lCurrColumn || '=' || AMyTabRec(lCurrColumn) || ',';
END LOOP;
But this of course does not work as I can't refefence the ROWTYPE by an numeric index, let alone by name. Any ideas how I could go about it in a different idea? Ideally I don't want to have to change this serialize method whenever I add a column to the table (i.e., should be "generic").