使用oracle脚本生成VO和Dao
Posted pluto-charon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用oracle脚本生成VO和Dao相关的知识,希望对你有一定的参考价值。
话不多说直接上代码。
生成VO的脚本:
SELECT ‘/**‘ || T2.COMMENTS || ‘*/ @Column(name="‘ || T1.COLUMN_NAME || ‘")‘ || ‘private ‘ || CASE WHEN T1.DATA_TYPE LIKE ‘VARCHAR%‘ THEN ‘String ‘ WHEN T1.DATA_TYPE LIKE ‘DATE%‘ THEN ‘Date ‘ WHEN T1.DATA_SCALE <> NULL OR T1.DATA_SCALE <> 0 THEN ‘Double ‘ WHEN T1.DATA_TYPE LIKE ‘NUMBER%‘ THEN ‘int ‘ WHEN T1.DATA_TYPE LIKE ‘Timestamp%‘ THEN ‘Timestamp ‘ END || LOWER(SUBSTR(T1.COLUMN_NAME, 1, 1)) || SUBSTR(REPLACE(INITCAP(T1.COLUMN_NAME), ‘_‘, ‘‘), 2) || ‘;‘ FROM USER_TAB_COLUMNS T1, USER_COL_COMMENTS T2 WHERE T1.TABLE_NAME = T2.TABLE_NAME AND T1.COLUMN_NAME = T2.COLUMN_NAME AND T1.TABLE_NAME IN (‘表名‘)
生成DaO的脚本:
SELECT ‘/**‘ || T2.COMMENTS || ‘*/ ‘ || ‘private ‘ || CASE WHEN T1.DATA_TYPE LIKE ‘VARCHAR%‘ THEN ‘String ‘ WHEN T1.DATA_TYPE LIKE ‘DATE%‘ THEN ‘Date ‘ WHEN T1.DATA_SCALE <> NULL OR T1.DATA_SCALE <> 0 THEN ‘Double ‘ WHEN T1.DATA_TYPE LIKE ‘NUMBER%‘ THEN ‘int ‘ WHEN T1.DATA_TYPE LIKE ‘Timestamp%‘ THEN ‘Timestamp ‘ END || LOWER(SUBSTR(T1.COLUMN_NAME, 1, 1)) || SUBSTR(REPLACE(INITCAP(T1.COLUMN_NAME), ‘_‘, ‘‘), 2) || ‘;‘ FROM USER_TAB_COLUMNS T1, USER_COL_COMMENTS T2 WHERE T1.TABLE_NAME = T2.TABLE_NAME AND T1.COLUMN_NAME = T2.COLUMN_NAME AND T1.TABLE_NAME IN (‘表名‘)
将生成出来的数据复制到Java类里,格式化就OK了。
以上是关于使用oracle脚本生成VO和Dao的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Toad for Oracle 中使用自定义代码片段?