hibernate 判断表是否存在
- 作者: 神圣PLA
- 来源: 51数据库
- 2021-01-20
不知道你是想怎么判断,但是select table_name from user_tables;就会查询出所有的表名字(不区分大小写);
你要是用hibernate注入的话,在配置文件中直接弄成update,那么有表的时候就不会创建表,没有的时候就会创建一个表。
要是想在数据库内判断的话,就要用到function和procedure来循环判断做,要不就不知道怎么弄了,看你想怎么弄吧。
declare
vl_num number(8);
strsql_create varchar2(1024);
begin
select count(*) into vl_num from tabs where table_name='testtb';
if ( vl_num = 0 ) then
strsql_create := 'create table testtb(id int,name varchar(20) )';
execute immediate strsql_create;
end if;
end;
你要是用hibernate注入的话,在配置文件中直接弄成update,那么有表的时候就不会创建表,没有的时候就会创建一个表。
要是想在数据库内判断的话,就要用到function和procedure来循环判断做,要不就不知道怎么弄了,看你想怎么弄吧。
declare
vl_num number(8);
strsql_create varchar2(1024);
begin
select count(*) into vl_num from tabs where table_name='testtb';
if ( vl_num = 0 ) then
strsql_create := 'create table testtb(id int,name varchar(20) )';
execute immediate strsql_create;
end if;
end;
推荐阅读
