zoukankan      html  css  js  c++  java
  • 【SQL】INTERVAL YEAR TO MONTH 和 INTERVAL DAY TO SECOND

    INTERVAL YEAR TO MONTH: 作为年和月的时间间隔存储

    INTERVAL DAY TO SECOND: 作为天、小时、分和秒的时间间隔存储(DAY,HOUR,MINUTE,SECOND)

    1) 创建以上两种数据类型的表

    SQL> create table t1(id number(2),x interval year to month,y interval day to second);

    Table created.

    SQL> desc t1;
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ------------------------------------
     ID                                                             NUMBER(2)
     X                                                              INTERVAL YEAR(2) TO MONTH
     Y                                                              INTERVAL DAY(2) TO SECOND(6)

    2) x字段插入:5年,y字段插入:2天

    SQL> insert into t1 values (1,interval '5' year,interval '2' day);

    1 row created.

    SQL> commit;

    Commit complete.

    SQL> select * from t1;

            ID X                    Y
    ---------- -------------------- --------------------
             1 +05-00               +02 00:00:00.000000

    3) x字段插入:10个月,y字段插入:2小时

    SQL> insert into t1 values (2,interval '10' month,interval '2' hour);

    1 row created.

    SQL> commit;

    Commit complete.

    SQL> select * from t1;

        ID     X                    Y
    ---------- -------------------- --------------------
         1     +05-00               +02 00:00:00.000000
         2     +00-10               +00 02:00:00.000000

    4) x字段插入:2年零6个月,y字段插入:1天量12小时30分钟1秒

    SQL> insert into t1 values (3,interval '2-6' year to month,interval '1 12:30:01' day to second);

    1 row created.

    SQL> commit;

    Commit complete.

    SQL> select * from t1;

        ID     X                    Y
    ---------- -------------------- --------------------
         1     +05-00               +02 00:00:00.000000
         2     +00-10               +00 02:00:00.000000
         3     +02-06               +01 12:30:01.000000



  • 相关阅读:
    OC3(字符串,值类)
    OC2(初始化方法)
    OC1(类和对象)
    postgresql 时间戳格式为5分钟、15分钟
    centos添加ftp用户并禁止外切目录
    postgresql 判断日期是否合法
    tigerVNC的简单使用教程(CentOS的远程桌面连接)
    linux awk解析csv文件
    由windows向linux上传下载文件方法
    codeblocks linux编译告警乱码解决办法
  • 原文地址:https://www.cnblogs.com/NextAction/p/7366638.html
Copyright © 2011-2022 走看看