oracle11g - 如果没有一个完整的键保留表,则无法从视图中删除
问题描述
目前,我想从不同的购物车表中删除该用户的商品。所以我想出了它。
DELETE FROM (SELECT *
FROM EXH_CART EC, PRODUCT_CART PC, MEMBER M
WHERE PC.USER_NUM(+) = M.USER_NUM
AND EC.USER_NUM(+) = M.USER_NUM
AND M.USER_NUM = 6);
但是这段代码给了我这个错误。
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 had
- no key-preserved tables;
- more than one key-preserved table, or
- the key-preserved table was an unmerged view.
*Action: Redefine the view or delete it from the underlying base tables.
我该如何解决这个错误?请帮忙。
解决方案
Per the documentation of the DELETE command (https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_8005.htm#SQLRF01505), the syntax does not support multiple tables, joins, or other similar constructs. You must issue separate delete commands for each related table:
DELETE FROM MEMBER M WHERE M.USER_NUM = 6;
DELETE FROM EXH_CART EC WHERE EC.USER_NUM = 6;
DELETE FROM PRODUCT_CART PC WHERE PC.USER_NUM = 6;
COMMIT;
As I mentioned in the comments, ideally you would have a formal foreign key relationship between the child and parent tables, with the ON DELETE CASCADE
option set so that you would then only have to delete the record from the parent table and let the database handle the child records automatically.
推荐阅读
- python - pyautogui 没有将屏幕截图保存到我告诉它的目录
- django - Django模板中的嵌套字典
- php - 如何dockerize一个微服务php应用程序?
- javascript - Javascript CSS 星级评分系统悬停
- computation-theory - 如何绘制语言 A={w | 的 DFA w 的每个偶数位置都有符号 0}?
- reactjs - ForEach API 调用反应状态未正确更新
- asp.net-mvc - 如何使用 MVC 根据数据库设置在导航栏中显示/隐藏链接
- linux - 在 Linux 中创建文件的权限被拒绝
- java - 角度水平计算,android studio
- java - Spring Kafka 批处理错误处理程序 - 手动提交的 DeSerialiser 错误处理