通过SQL的方式将表字段列转换为Java代码驼峰字段的SQL脚本:
select colName,case when line=0 then colName else head||upper end field from
(
select lower(column_name) as colName, instr(lower(column_name),'_') line,
substr(lower(column_name),0,instr(lower(column_name),'_')-1) head,
replace(initcap(substr(lower(column_name),instr(lower(column_name),'_')+1)),'_','') upper
from user_tab_columns where lower(table_name) = 'XXX'
);
生成java代码:
select colName,case when line=0 then dataType || colName || ';' else dataType || head||upper ';' end field from
(
select lower(column_name) as colName, instr(lower(column_name),'_') line,
substr(lower(column_name),0,instr(lower(column_name),'_')-1) head,
replace(initcap(substr(lower(column_name),instr(lower(column_name),'_')+1)),'_','') upper,
case when data_type = 'NUMBER' then 'private Integer ' when data_type='VARCHAR2' then 'private String ' when data_type = 'TIMESTAMP(0)' then 'private DateTime ' else data_type end dataType
from user_tab_columns where lower(table_name) = 'XXX'
);
生成java代码包括列注释:
select colName,
'/**' || comments || '*/' || chr(9) || (case
when line = 0 then
dataType || colName || ';'
else
dataType || head || upper ';'
end) field,
comments
from (select lower(t1.column_name) as colName,
instr(lower(t1.column_name), '_') line,
substr(lower(t1.column_name),
0,
instr(lower(t1.column_name), '_') - 1) head,
replace(initcap(substr(lower(t1.column_name),
instr(lower(t1.column_name), '_') + 1)),
'_',
'') upper,
case
when t1.data_type = 'NUMBER' then
'private Integer '
when t1.data_type = 'VARCHAR2' then
'private String '
when t1.data_type = 'TIMESTAMP(0)' then
'private DateTime '
else
t1.data_type
end dataType,
t2.comments
from user_tab_columns t1
left join user_col_columns t2 on t1.table_name = t2.table_name
and t1.column_name = t2.column_name
where lower(t1.table_name) = 'XXX');