Oracle 默认列值计算日期

发布于 2024-12-15 04:53:00 字数 110 浏览 2 评论 0原文

我正在尝试创建一个表,该表的日期默认值为 sysdate - 2 在 oracle 中

Oracle 似乎可以使用 sysdate 作为默认值,但不能使用 sysdate - 2。这可能吗?

I am trying to create a table that has a default value for a date that is sysdate - 2 in oracle

Oracle seems to be fine with sysdate as the default but not sysdate - 2. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2024-12-22 04:53:00

您需要在括号中指定默认值:

创建表:

CREATE TABLE order_status (
  order_id NUMBER,
  last_modified DATE DEFAULT (SYSDATE - 2)
);

插入一条记录来测试默认值:

INSERT INTO order_status
(order_id)
VALUES
(1);

从表中选择数据以确认默认值有效(当前日期 14/11/2011):

SELECT *
  FROM order_status;

ORDER_ID  LAST_MODIFIED
       1  12/11/2011

DB 版本 10g。

希望它有帮助...

You need to specify the DEFAULT value in brackets:

Create the table:

CREATE TABLE order_status (
  order_id NUMBER,
  last_modified DATE DEFAULT (SYSDATE - 2)
);

Insert a record to test the default:

INSERT INTO order_status
(order_id)
VALUES
(1);

Select the data from the table to confirm the default worked (Current date 14/11/2011):

SELECT *
  FROM order_status;

ORDER_ID  LAST_MODIFIED
       1  12/11/2011

DB Version 10g.

Hope it helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文