Guest User

Untitled

a guest
Oct 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. CREATE OR REPlACE PROCEDURE DELETE_CUSTOMER
  2. (CUSTOMER_ID NUMBER) AS
  3. TOT_CUSTOMERS NUMBER;
  4. BEGIN
  5. DELETE FROM CUSTOMERS
  6. WHERE CUSTOMERS.CUSTOMER_ID = DELETE_CUSTOMER.CUSTOMER_ID;
  7. TOT_CUSTOMERS := TOT_CUSTOMERS - 1;
  8. END;
  9. /
  10.  
  11. EXECUTE DELETE_CUSTOMER(01);
  12.  
  13. Error starting at line : 120 in command -
  14. BEGIN DELETE_CUSTOMER(01); END;
  15. Error report -
  16. ORA-02292: integrity constraint (TUG81959.ORDERS_FK_CUSTOMERS) violated - child record found
  17. ORA-06512: at "TUG81959.DELETE_CUSTOMER", line 5
  18. ORA-06512: at line 1
  19. 02292. 00000 - "integrity constraint (%s.%s) violated - child record found"
  20. *Cause: attempted to delete a parent key value that had a foreign
  21. dependency.
  22. *Action: delete dependencies first then parent or disable constraint.
  23.  
  24. CREATE OR REPlACE PROCEDURE DELETE_CUSTOMER
  25. (CUSTOMER_ID_IN NUMBER) AS
  26. TOT_CUSTOMERS NUMBER;
  27. CURSOR C1 IS
  28. DELETE FROM ORDERS
  29. WHERE ORDERS.ORDER_ID = CUSTOMER_ID.ORDER_ID;
  30. CURSOR C2 IS
  31. DELETE FROM ORDER_DETAILS
  32. WHERE ORDER_DETAILS.ORDER_ID = CUSTOMER_ID.ORDER_ID;
  33. CURSOR C3 IS
  34. DELETE FROM CUSTOMERS
  35. WHERE CUSTOMERS.CUSTOMER_ID = DELETE_CUSTOMER.CUSTOMER_ID;
  36. BEGIN
  37. OPEN C1;
  38. OPEN C2;
  39. OPEN C3;
  40. IF C1%FOUND AND C2%FOUND AND C3%FOUND
  41. THEN TOT_CUSTOMERS := TOT_CUSTOMERS - 1;
  42. END IF;
  43. CLOSE C1;
  44. CLOSE C2;
  45. CLOSE C3;
  46. END;
  47. /
Add Comment
Please, Sign In to add comment