Note that there are some explanatory texts on larger screens.

plurals
  1. POInstantiating oracle object type using a type name in varchar2
    primarykey
    data
    text
    <p>Initial situation:</p> <ul> <li> I have a typename in a variable: </li> <code>type_name varchar2(20) := 'T_MY_TYPE';</code> <li> T_SUPERTYPE is a supertype of T_MY_TYPE </li> <li> T_MY_TYPE overrides a single method to provide specific behavior. </li> <li> The constructor function of my self defined object type T_MY_TYPE has no parameters. </li> <li> I need to create a type instance using the given variable. </li> <li> The created instance has to be assigned to a variable of the supertype T_SUPERTYPE. </li> <li> Oracle Version: 11.2.0.2.0, Developing with PL/SQL Developer 10.0.1 </li> </ul> <p>My failed attempt:</p> <pre> <code> declare type_name varchar2(20) := 'T_MY_TYPE'; myInstance T_SUPERTYPE; begin execute immediate 'myInstance := ' || type_name || '()'; -- Fails with ORA-00900: Invalid SQL statement -- tried alternative: exceute immediate 'select ' || type_name || '() from dual into myInstance'; -- doesn't work either (ORA-00933: SQL command not properly ended) end; </code> </pre> <p>Additional Information: I want to use a couple of object types that all inherit from one single supertype. All inheriting subtypes differ only in the implementation of a single method. In the end i will have a function that iterates over a number of varchar2 ( the type names), instantiates all types and calls the functions (all same name, but do different things because of the different implementation). The different subtypes contain some convenience stuff and forces the developer to stick to the rules by inheriting from the supertype. So i just want to use the classic advantage of polymorphism.</p> <p>As PL/SQL is definetly not my native language, i will appreciate any suggestion :)</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.
 

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