Disclaimer

The views and opinions expressed in this blog are my own and do not necessarily reflect those of my employer. The views and opinions expressed by visitors to this blog are theirs and do not necessarily reflect my own

Tuesday, June 19, 2007

Create table as select for LOV generation

If your creating Apex applications on a regular basis then sooner or later you will have made use of LOVs. Recently I needed to create an lov using the data contained within USER_TAB_COLS as a starting point. A feature of Oracle DDL allows you to create and populate a table from a sql query. For example
create table test_lov_table as
    init_caps(replace(COLUMN_NAME,'_', '  ')) COLUMN_NAME
    ,CHAR_LENGTH
from user_tab_cols
where TABLE_NAME = 'my_table';
The above code only serves as an example but got me thinking whether this technique could be useful anywhere else. Purely speculating I thought that this could be something to consider if your migrating data from older systems and need to take portions of your data model to create reference data tables for LOVs. Another purely hypothetical situation where this may speed things up is where you need to map one schema's tables, columns to another's tables and columns (through the respective user_tab_cols table) i.e for the purpose of interfacing two data models again.