Skip to content

Instantly share code, notes, and snippets.

@marcelocg
Created November 8, 2019 11:08
Show Gist options
  • Select an option

  • Save marcelocg/c036531bb336421db2f3e3721f561505 to your computer and use it in GitHub Desktop.

Select an option

Save marcelocg/c036531bb336421db2f3e3721f561505 to your computer and use it in GitHub Desktop.
Generate JPA annotations for each column of a given Oracle Table
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