Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Prosedur untuk menghapus hanya jika database lebih tinggi dari sysdate

kondisi ini dapat Anda tambahkan di awal prosedur sebagai berikut -

PROCEDURE Remove_Customer(Customer_Id VARCHAR2) IS
  l_Order_Date DATE;
BEGIN
  BEGIN
    SELECT MAX(Delivery_Date)
      INTO l_Order_Date
      FROM Placed_Order
     WHERE Placed_Order.Fk1_Customer_Id = Customer_Id;
  EXCEPTION
    WHEN OTHERS THEN
      l_Order_Date := SYSDATE - 1;
  END;
  IF l_Order_Date < SYSDATE THEN
    DELETE FROM Order_Line
     WHERE Order_Line.Fk1_Order_Id IN
           (SELECT Order_Id
              FROM Placed_Order
             WHERE Placed_Order.Fk1_Customer_Id = Customer_Id);
    DELETE FROM Placed_Order
     WHERE Placed_Order.Fk1_Customer_Id = Customer_Id;
    DELETE FROM Customer WHERE Customer.Customer_Id = Customer_Id;      
    --Total_Customers := Total_Customers - 1; -- is it a global variable in the package?
  ELSE
    Dbms_Output.Put_Line('Customer currently has a order been delivered');
  END IF;
END;



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. ORA-28113:predikat kebijakan memiliki kesalahan

  2. dua kunci asing ke tipe data numerik yang sama dan merujuknya ke dua tabel

  3. Masalah Koneksi Intermiten Oracle JDBC

  4. Menggunakan cakupan transaksi dan kueri

  5. Matriks Versi yang Didukung Oracle