Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically accessing member of a User-defined objects in PL/SQL
    primarykey
    data
    text
    <p>Is there any way to access a dynamically accessing member of a User- defined record, object or reference cursor using a variable? E.g. Something like</p> <pre><code> get_member(my_object, 'member name'); </code></pre> <p>Or maybe</p> <pre><code> my_object.$'member name'; </code></pre> <p>EXECUTE IMMEDIATE won't work as it does not operate within the scope of my procedure.</p> <p>Let me brifly explain what i am trying to accomplish. I have a mapping table M which describes how records of table A should be transformed into records of table B. The mapping must vary according the specific type of record in A (given by A.type). I wanted to perform the mapping something like this (not exactly, planning on encapsulating the mapping logic inside a stream function, but the principle remains similar):</p> <pre><code>SELECT ... CASE WHEN M.field_1_mapping IS NOT NULL THEN -- column of A given by value of M.field_1_mapping ELSE null -- field_1 not filled for record type END field_1, --- etc. FROM table_a A, mapping_table M WHERE A.TYPE = M.TYPE </code></pre> <p>So my question is how I might do this. Again i cannot use dynamic SQL as it has to different for each record type, but if column could be selected based on the value of the mapping field then the obovemention sql would work. </p> <p>I realize that it simply might not be possible (and may go against the PL/SQL design philosophy), in which case i would welcome any suggestions you might have as to how this problem could be solved.</p> <p>P.S: I suppose it would be possible to simply hard-code a mapping function e.g.:</p> <pre><code>FUNCTION get_field(field_key IN VARCHAR(32), a NOCOPY IN table_a%rowtype) RETURN VARCHAR(2000) IS out VARCHAR2(2000) BEGIN -- ... IF field_key = 'field_1' THEN RETURN a.field_1; END IF; -- .. END; </code></pre> <p>But that seems really inelegant.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload