Delete rows matching substring with LIKE?

我是研究僧i 提交于 2019-12-13 16:34:57

问题


How do you delete rows from a table, where a column contains a substring, but the type of that column is 'Long'. (Yes, I know I shouldn't use Long, but I'm maintaining someone else's mess).

My first attempt was:

delete from longtable 
  where search_long(rowid) like '%hello%';  

(Following on from this answer.)

This returns:

SQL Error: ORA-04091: table blah.longtable is mutating, trigger/function may not see it


回答1:


I just replicated your problem and got the same error - it seems the function can't work from within a DELETE statement. The full text of the error is:

ORA-04091: table HOU.LONGTABLE is mutating, trigger/function may not see it
ORA-06512: at "TONY.SEARCH_LONG", line 4

This procedural approach will work:

begin
  for r in (select id from longtable 
            where search_long(rowid) like '%hello%')
  loop
    delete longtable where id = r.id;
  end loop;
end;


来源:https://stackoverflow.com/questions/2381203/delete-rows-matching-substring-with-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!