plsql自動生成java原始碼

zgy13121發表於2008-09-25
plsql自動生成java原始碼[@more@]--注意表名用相應表名去替換下面的表名都為oper_log --fb/vo 屬性 column properties format a256; select 'private String '||LOWER(A.COLUMN_NAME)||';//'||B.COMMENTS properties FROM user_tab_cols A,user_col_comments B WHERE A.TABLE_NAME=B.TABLE_NAME AND LOWER(A.TABLE_NAME)='oper_log' and a.COLUMN_NAME=b.COLUMN_NAME ; --生成sql語句 --注意Sys_Connect_By_Path引數的欄位中有','時不能用','去分隔,改為用'@@',然後再替換為',' --用Sys_Connect_By_Path(COLUMN_NAME, ',')時將行轉換成列時,每一行都加',',所以第一個要去掉用substr(str,2) --對日期型的格式為'yyyy-mm-dd hh:MI:ss',可自己替換 column s format a200; Select replace('SELECT '||substr(Sys_Connect_By_Path(COLUMN_NAME, ','),2)||' FROM '||table_name||' WHERE 1=1','@@',',') S From ( SELECT Rownum Rid, DECODE(A.DATA_TYPE,'DATE', 'TO_CHAR('||A.COLUMN_NAME||'@@'||CHR(39)||'yyyy-mm-dd hh:MI:ss'||CHR(39)||') '||A.COLUMN_NAME, A.COLUMN_NAME) COLUMN_NAME,TABLE_NAME FROM USER_TAB_COLS A WHERE A.TABLE_NAME='OPER_LOG' ) Where Rid = ( Select Count(*) FROM USER_TAB_COLS A WHERE A.TABLE_NAME='OPER_LOG' ) start With Rid = 1 Connect By Prior Rid+1 = Rid ; --也可以寫成以下這種 column s format a200; --注意Sys_Connect_By_Path引數的欄位中有','時不能直接用','去分隔,改為用' , ' Select 'SELECT '||substr(Sys_Connect_By_Path(COLUMN_NAME, ' , '),4)||' FROM '||table_name||' WHERE 1=1' S From ( SELECT Rownum Rid, DECODE(A.DATA_TYPE,'DATE', 'TO_CHAR('||A.COLUMN_NAME||','||CHR(39)||'yyyy-mm-dd hh:MI:ss'||CHR(39)||') '||A.COLUMN_NAME, A.COLUMN_NAME) COLUMN_NAME,TABLE_NAME FROM USER_TAB_COLS A WHERE A.TABLE_NAME='OPER_LOG' ) Where Rid = ( Select Count(*) FROM USER_TAB_COLS A WHERE A.TABLE_NAME='OPER_LOG' ) start With Rid = 1 Connect By Prior Rid+1 = Rid ; --vo設定生成值 --oracle中的initcap與java裡的有點區別 --oracle裡如user_id用initcap取的是User_Id而java裡的是User_id,注意有下劃線的要手動修改 column s format a200; SELECT 'vo.set'||initcap(A.COLUMN_NAME)||'(dset.getString("'||A.COLUMN_NAME||'"));' s FROM USER_TAB_COLS A WHERE lower(A.TABLE_NAME)='oper_log' ;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11419868/viewspace-1011015/,如需轉載,請註明出處,否則將追究法律責任。

相關文章