我有我的SQL查詢問題。ORA-01843:不是有效的月份
create table rental
(
rental_id NUMBER(5) NOT NULL,
rental_date timestamp NOT NULL,
inventory_id NUMBER(5) NOT NULL,
customer_id NUMBER(5) NOT NULL,
return_date timestamp NOT NULL,
staff_id NUMBER(5) NOT NULL,
constraint rental_primary PRIMARY KEY (rental_id),
constraint rental_foreign FOREIGN KEY (inventory_id) REFERENCES
inventory(inventory_id),
constraint rental_foreign2 FOREIGN KEY (customer_id) REFERENCES
customer(customer_id),
constraint rental_foreign3 FOREIGN KEY (staff_id) REFERENCES staff(staff_id),
constraint rental_unique_rental_date unique (rental_date),
constraint rental_unique_inventory_id unique (inventory_id),
constraint rental_unique_customer_id unique (customer_id),
constraint rental_rental_date check(to_char(rental_date,'YYYY/MM/DD HH:MI:SS AM')
between '2005/01/01 00:00:01 AM' AND '12/31/2015 11:59:59 PM'),
constraint rental_return_date check(to_char(return_date,'YYYY/MM/DD HH:MI:SS AM')
between '2005/01/01 00:00:01 AM' AND '12/31/2015 11:59:59 PM')
);
當我試圖插入數據, 它拋出這個錯誤「ORA-01843:不是有效的月份」。 任何人都可以請建議我什麼類型的數據類型可以使用rental_date和返回日期來解決這種情況? 這裏是我試圖上傳
rental_date return_date
5/24/2011 10:53:30 PM 5/26/2011 10:04:30 PM
注意我的樣本數據:我可以在Excel工作表在那裏我有我的數據,但看到這種類型的格式,當我得到錯誤
"ORA-01843: not a valid month
Row 145: 144, 2011-05-25 23:49:56 ,1689,357, 2011-06-01 21:41:56 ,2"
我我在這裏觀察不同的時間格式。
任何人都可以建議我一個解決方案嗎?
在此先感謝。
請參考此鏈接瞭解我如何使用時間戳數據類型 http://www.techonthenet.com/oracle/functions/to_timestamp.php – Nina
您是否確實需要將這些字段聲明爲時間戳? –
這裏使用了兩種不同的日期格式。另外,考慮使用'to_date'而不是'to_char',以便比較日期而不是字符串。 –