使用LIKE删除与子字符串匹配的行?

时间:2010-03-04 17:09:02

标签: sql oracle sql-like sql-delete ora-04091

如何从表中删除行,其中列包含子字符串,但该列的类型为“Long”。 (是的,我知道我不应该使用Long,但我保持别人的混乱)。

我的第一次尝试是:

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

(继续this answer。)

返回:

  

SQL错误:ORA-04091:表blah.longtable正在变异,触发器/函数可能看不到它

1 个答案:

答案 0 :(得分:4)

我刚刚复制了你的问题并得到了同样的错误 - 看起来这个函数无法在DELETE语句中起作用。错误的全文是:

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

这种程序方法可行:

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