3

我有一个事务表,我的问题是跟踪该transactionDateTime列。使用 SQL,我似乎无法获取DATETIMESTAMP格式化,因此任何插入的数据都必须在任何一天的上午 8 点到晚上 10 点之间:

    CREATE TABLE Transaction_T
      (transactionID          NUMBER(8,0)              ,
       employeeID             NUMBER(10,0)      NOT NULL,
       customerID             NUMBER(6,0)       NOT NULL,
       transactionDate        VARCHAR2(9)       NOT NULL,
       transactionPayment     VARCHAR2(10) check(transactionPayment IN('cash','credit','debit','ebt')),
       transactionType        VARCHAR2(10) check(transactionType IN('void','return','sale')),
       transactionDateTime    TIMESTAMP check(transactionDateTime < '% 22:00:00' AND transactionDateTime > '% 08:00:00') NOT NULL,
CONSTRAINT TransactionPK PRIMARY KEY (transactionID),
CONSTRAINT TransactionFK1 FOREIGN KEY (employeeID) REFERENCES Employee_T(employeeID),
CONSTRAINT TranscationFK2 FOREIGN KEY (customerID) REFERENCES Customer_T(customerID));

上表已创建,但在尝试插入正确的 时Date(Time),我收到有关 1 到 12 小时之间的格式错误,或者当时间低于 12 时,我收到了无效月份。我使用了 Oracle 文档格式,但仍然没有运气:

INSERT INTO 
transaction_T(transactionID, employeeID, customerID, transactionDate, transactionPayment, transactionType, transactionDateTime) 
VALUES(00000001, 0001, 000004, '04-APR-13','ebt','sale','04-APR-13 13:25:10');
4

2 回答 2

8

你的%检查约束在这里不起作用。试试这个:

CHECK (
  EXTRACT(HOUR FROM transactionDateTime) < 22 AND
  EXTRACT(HOUR FROM transactionDateTime) >= 8)
于 2013-04-12T14:54:54.613 回答
1

您可以像这样表达您的检查约束:

check(transactionDateTime between trunc(transactionDateTime) + 8/24 and trunc(transactionDateTime) + 22/24))
于 2013-04-12T14:54:09.203 回答