我在上一篇文章(https://stackoverflow.com/questions/16520216/ora-01843-not-a-valid-month)中提出過這個問題,但從那時起它就發生了變化,我認爲最好從頭開始更清楚一點。爲什麼我得到ORA-01843:不是有效的月份錯誤?
運行過程從客戶表中刪除客戶時,我收到此錯誤。
BEGIN
customers.remove_customer('17023');
END;
然而,當我刪除客戶表中的客戶一個觸發器觸發這是我認爲問題在於,這裏是觸發代碼:
create or replace TRIGGER CUSTOMER_AD
BEFORE DELETE ON CUSTOMER
REFERENCING OLD AS OLD
FOR EACH ROW
DECLARE
pragma autonomous_transaction;
nPlaced_order_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO nPlaced_order_count
FROM PLACED_ORDER p
WHERE p.FK1_CUSTOMER_ID = :OLD.CUSTOMER_ID;
IF nPlaced_order_count > 0 THEN
INSERT into previous_customer
(customer_id,
first_name,
last_name,
address)
VALUES
(:old.customer_id,
:old.first_name,
:old.last_name,
:old.address);
END IF;
END CUSTOMER_AD;
現在,當我刪除客戶誰沒有記錄在已放置的訂單表中記錄被刪除正常,當試圖刪除在已訂購的訂單表中有記錄的客戶時會出現錯誤消息。因此,我認爲錯誤發生在觸發器中,因爲如果觸發器只在prede_customer表中插入值,那麼它們在place_order表中有記錄。但我仍然不明白爲什麼我會收到我的錯誤消息?
客戶表上沒有其他觸發器。 的放置順序表上有沒有其他觸發器和既不確實的previous_employee
爲客戶表中的結構是:
"CUSTOMER_ID" VARCHAR2(40) NOT NULL ENABLE,
"FIRST_NAME" VARCHAR2(30),
"LAST_NAME" VARCHAR2(30),
"ADDRESS" VARCHAR2(30)
CONSTRAINT "PK_CUSTOMER" PRIMARY KEY ("CUSTOMER_ID") ENABLE
爲placed_order結構是:
"ORDER_ID" NUMBER(*,0) NOT NULL ENABLE,
"ORDER_DATE" VARCHAR2(15),
"DELIVERY_DATE" VARCHAR2(15),
"FK1_CUSTOMER_ID" VARCHAR2(40) NOT NULL ENABLE,
CONSTRAINT "PK_PLACED_ORDER" PRIMARY KEY ("ORDER_ID") ENABLE
ALTER TABLE "PLACED_ORDER" ADD CONSTRAINT "FK1_PLACED_ORDER_TO_CUSTOMER" FOREIGN KEY ("FK1_CUSTOMER_ID")
REFERENCES "CUSTOMER" ("CUSTOMER_ID") ON DELETE CASCADE ENABLE
和結構for previous_customer是:
"CUSTOMER_ID" VARCHAR2(40),
"FIRST_NAME" VARCHAR2(30),
"LAST_NAME" VARCHAR2(30),
"ADDRESS" VARCHAR2(30)
任何人都知道爲什麼我得到錯誤消息ORA-01843?
程序代碼是:
PROCEDURE remove_customer (customer_id VARCHAR2) IS
ordersCount pls_integer;
BEGIN
select count(*) into ordersCount
from placed_order
where fk1_customer_id = remove_customer.customer_id
and delivery_date > sysdate;
IF ordersCount > 0
THEN
DBMS_OUTPUT.PUT_LINE ('Customer currently has a order been delivered and cant be deleted');
ELSE
DELETE FROM customer
WHERE customer.customer_id = remove_customer.customer_id;
total_customers := total_customers - 1;
END IF;
END;
您顯示的內容沒有解釋錯誤。查找試圖將一列'placed_order.delivery_date'和'placed_order.order_date'解析爲實際日期或日期時間對象的代碼。 – 2013-05-13 15:50:47
爲什麼你認爲觸發是問題的根源?如果在任何表格或代碼中沒有「DATE」列,觸發器導致錯誤的可能性很小。爲什麼觸發器是一個自主事務?這幾乎肯定是一個錯誤。雖然它可能不是這個特定bug的來源。 – 2013-05-13 15:51:17
如果觸發器是問題,那麼只需運行...刪除客戶id = ...應該得到同樣的問題。可以? – Dave 2013-05-13 16:02:31