异常ORA-08103:使用Hibernate的setfetchsize时对象不再存在

Bar*_*ney 11 sql oracle hibernate exception

我正在使用Hibernate.我需要获取大约1000000条记录,这将导致超时异常.所以我使用setfetchsize了6000条记录,因此它将在每条6000条记录的多个交易中分配操作.

获取所有内容大约需要21个小时.

但同时检索记录,如果有人删除了要获取的记录之一,那么我得到ORA-08103: object no longer exists.

现在我想跳过检索时删除的对象.我怎样才能做到这一点?

Nic*_*nov 15

很可能是基于全局临时表(GTT)打开游标,该表是使用ON COMMIT DELETE ROWS选项创建的.并且ORA-08103: object no longer exists错误的原因是commit紧跟在delete语句之后的语句.这是一个简单的例子:

 SQL> declare
  2    type t_recs is table of number;
  3    l_cur sys_refcursor;    -- our cursor
  4    l_rec t_recs; 
  5  
  6  begin
  7  
  8    -- populating a global temporary table GTT1 with sample data  
  9    insert into GTT1(col)
 10      select level
 11        from dual
 12     connect by level <= 1000;
 13  
 14   open l_cur         -- open a cursor based on data from GTT1
 15    for select col
 16          from GTT1;
 17  
 18    -- here goes delete statement
 19    -- and
 20    commit;  <-- cause of the error. After committing  all data from GTT1 will be
 21              -- deleted and when we try to fetch from the cursor
 22    loop      -- we'll face the ORA-08103 error
 23      fetch l_cur    -- attempt to fetch data which are long gone.
 24       bulk collect into l_rec;
 25      exit when l_cur%notfound;
 26    end loop;
 27  
 28  end;
 29  /


ORA-08103: object no longer exists
ORA-06512: at line 24
Run Code Online (Sandbox Code Playgroud)

重新创建全局临时表with on commit preserve rows子句将允许从基于该表的游标安全地获取数据,而不用担心面临 ORA-08103:错误.

  • @Ben如果你正在一个`insert select`语句正在截断一个表,是的,你将得到相同的错误只是因为`select`语句是一个游标和`truncate`语句,因为它是一个DDL语句,导致双提交 - 截断之前然后之后. (5认同)