Skip to main content

Get C# class declaration from Oracle Table

Select distinct
'public ' ||
case Lower(DATA_TYPE)
             when 'raw' then 'Guid?'
             when 'number' then 'Decimal?'
            when 'char' then 'string'
            when 'date' then 'DateTime?'
            when 'decimal' then 'decimal?'
            when 'nvarchar' then 'string?'
            when 'uniqueidentifier' then 'Guid?'
            when 'varchar2' then 'string'
            else 'UNKNOWN_' || DATA_TYPE
end|| ' '
 || replace(initcap(replace(Column_name,'_',' ')),' ','') || ' { get; set; }' ,
 all_tab_columns.column_id
  from all_tab_columns where table_name= upper('SPA_DISCOUNT_GROUP')
  order by all_tab_columns.column_id

select *   from all_tab_columns where table_name= upper('SPA_DISCOUNT_GROUP')


--------------- Result --------------

    'PUBLIC'||CASELOWER(DATA_TYPE) COLUMN_ID
1 public Decimal? RefUniqueNo { get; set; }           1
2 public string Reference { get; set; }                   2
3 public string DiscType { get; set; }                   3
4 public Decimal? DiscPct { get; set; }                   4
5 public Guid? DiscountGroupKey { get; set; }     5
6 public Guid? ReferenceRef { get; set; }                   6

Comments