以前使用JPA Eclipse2.5和Oracle数据库以及glassfish4.0应用程序服务器的项目。我只想通过元数据生成数据库。但它会生成视图pojo(以前的项目管理器为@Entity激活了一个pojo,用于在oracle中创建的每个视图)到表。现在,我只想按元数据生成所有表。 persistense.xml就像这样:
<property name="javax.persistence.schema-generation.database.action" value="create" />
<property name="javax.persistence.schema-generation.create-source" value="metadata-then-script" />
<property name="javax.persistence.schema-generation.create-script-source" value="META-INF/sql/create1.sql" />
create1.sql中的只想放弃不必要表:
begin
for table_record in (select table_name from user_tables where table_name like 'V_%')
loop
execute immediate 'DROP TABLE ' || table_record.table_name ;
dbms_output.put_line('Table ' || table_record.table_name || ' dropped' );
end loop;
end;
但它不起作用。日志报告:
Local Exception Stack:
异常[EclipseLink-4002](Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.DatabaseException 内部异常:java.sql.SQLException:ORA-06550:֚1ѐ,֚101: PLS-00103:ԶЖػۅ“文件结束”ѨҪЂ֮һʱú (开始案例 如果loop mod null pragma raise return,则声明为goto退出 用时选择更新 &LT;&LT; 继续关闭当前删除获取锁定插入打开回滚 savepoint set sql execute commit forall merge pipe purge
Error Code: 6550
Call: begin for table_record in (select table_name from user_tables where table_name like 'V_%') loop
Query: DataModifyQuery(sql="begin for table_record in (select table_name from user_tables where table_name like 'V_%') loop")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
答案 0 :(得分:0)
要删除绑定完整性约束,必须将其添加到sql 级联约束。
begin
for table_record in (select table_name from user_tables where table_name like 'V_%')
loop
execute immediate 'DROP TABLE ' || table_record.table_name ||' cascade constraints ';
end loop;
end;
答案 1 :(得分:0)
要诊断错误,您必须添加异常处理。很可能这些表不能通过SQL游标打开这些表而删除,并且有锁可以删除表。您需要使用这些表关闭应用程序并删除sqlplus或sql developer或TOAD中的表 例。 如果另一个会话使用表,我们删除它,我们得到错误号ORA-00054。
begin
for table_record in (select table_name from user_tables where table_name like 'TEST1%')
loop
execute immediate 'DROP TABLE ' || table_record.table_name ;
dbms_output.put_line('Table ' || table_record.table_name || ' dropped' );
end loop;
exception
when OTHERS then
dbms_output.put_line(SQLCODE || ':' || SQLERRM);
end;
ORA-00054: resource busy and acquire with NOWAIT specified
要在一行上调用sql,您需要创建一个存储过程,并在一行中调用存储过程。
create or replace procedure DROP_TABLES_V IS
begin
for table_record in (select table_name from user_tables where table_name like 'TEST1%')
loop
execute immediate 'DROP TABLE ' || table_record.table_name ;
dbms_output.put_line('Table ' || table_record.table_name || ' dropped' );
end loop;
exception
when OTHERS then
dbms_output.put_line(SQLCODE || ':' || SQLERRM);
end;
在一行中调用存储过程。
begin DROP_TABLES_V; end;