Created
November 8, 2019 11:08
-
-
Save marcelocg/c036531bb336421db2f3e3721f561505 to your computer and use it in GitHub Desktop.
Generate JPA annotations for each column of a given Oracle Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set serveroutput on; | |
| declare | |
| nm_table varchar(100) := 'NOTA_FISCAL_HIST'; | |
| nm_nullable varchar(100); | |
| begin | |
| for r in ( select c.* from all_tables t | |
| inner join all_tab_columns c | |
| on c.TABLE_NAME = t.TABLE_NAME | |
| where t.TABLE_NAME = nm_table | |
| order by c.column_id | |
| ) | |
| loop | |
| if r.NULLABLE = 'N' then | |
| nm_nullable := ', nullable = false'; | |
| else | |
| nm_nullable := ''; | |
| end if; | |
| if r.DATA_TYPE = 'DATE' then | |
| dbms_output.put_line('@Temporal(TemporalType.TIMESTAMP)'); | |
| dbms_output.put_line('@Column(name = "'|| r.COLUMN_NAME ||'"'||nm_nullable); | |
| ELSIF r.DATA_TYPE = 'NUMBER' then | |
| dbms_output.put_line('@Column(name = "'|| r.COLUMN_NAME ||'"'|| nm_nullable || ', length = '|| r.DATA_PRECISION ||')'); | |
| else | |
| dbms_output.put_line('@Column(name = "'|| r.COLUMN_NAME ||'"'|| nm_nullable || ', length = '|| r.DATA_LENGTH ||')'); | |
| end if; | |
| dbms_output.put_line(''); | |
| end loop; | |
| end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment