日期:2014-05-16  浏览次数:20807 次

请大家分析如下语句,看oracle是怎么工作的?
delete from(
select 1
  from cust_interest a, cust_basicinfo b
 where a.cust_no = b.cust_no
  and b.cust_status <> '0');
这个语句是删除cust_interest表中的数据,我就是不知道oracle怎么确定删除cust_interest表而不是cust_basicinfo表数据,
请大家指导一下,谢谢。

------解决方案--------------------
呵呵,不但是你不知道,连ORACLE也不太清楚吧。
这个语句执行的时候会报错。

SQL Error: ORA-01752: cannot delete from view without exactly one key-preserved table
01752. 00000 - "cannot delete from view without exactly one key-preserved table"
*Cause: The deleted table either had no key perserved tables,
had more than one key-preserved table, or the key-preserved
table was an unmerged view or a table from a read-only view.
*Action: Redefine the view or delete it from the underlying base tables.

------解决方案--------------------
SQL code
[Quote=引用:]
delete from(
select 1
  from cust_interest a, cust_basicinfo b
 where a.cust_no = b.cust_no
  and b.cust_status <> '0');
这个语句是删除cust_interest表中的数据,我就是不知道oracle怎么确定删除cust_interest表而不是cust_basicinf……
[/Quote]


这个语句本身写法,我都觉得没有见过!

------解决方案--------------------
同样表示没有见过,同样求解。。。

探讨
SQL code
[Quote=引用:]
delete from(
select 1
from cust_interest a, cust_basicinfo b
 where a.cust_no = b.cust_no
and b.cust_status <> '0');
这个语句是删除cust_interest表中的数据,我就……

------解决方案--------------------
探讨
to 兰兰姐:你执行报这个错应该是你测试脚本中表的主键定义不合这种写法的规范,如果合规,肯定是能执行的。