1

この SQL を Oracle で実行しています (Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production):

CREATE TABLE R_SEQUENCES_COUNT1
  (
    DS_ID NUMBER,
    LINE_TIME TIMESTAMP(6),
    DAY_ID  DATE GENERATED ALWAYS   AS (TRUNC(LINE_TIME)),
    HOUR_ID  DATE GENERATED ALWAYS  AS (TRUNC(LINE_TIME,'HH24')) ,
    MINUTE_ID DATE GENERATED ALWAYS AS (TRUNC(LINE_TIME,'MI')) ,
    SECOND_ID DATE GENERATED ALWAYS AS (LINE_TIME),
    R_ID       NUMBER,
    SEQUENCE_ID NUMBER
  )NOLOGGING
  TABLESPACE TWC_DATA_SPACE
  PARTITION BY LIST (DS_ID)
  SUBPARTITION BY LIST(DAY_ID)
  (PARTITION DS_ID_OTHER VALUES (DEFAULT) 
  (SUBPARTITION DS_ID_OTHER_DAY_ID_OTHER VALUES (DEFAULT)))

そして、このエラーを取得します:

Error at Command Line:8 Column:40
Error report:
SQL Error: ORA-54016: Invalid column expression was specified

なにが問題ですか?

4

2 に答える 2

1

日付として使用する場合は、次のようにします。

SECOND_ID DATE GENERATED ALWAYS AS (cast(LINE_TIME as date)),

それ以外の場合は、次のことができます。

SECOND_ID TIMESTAMP GENERATED ALWAYS AS (LINE_TIME + numtodsinterval(0, 'day')),

ただし、その場合、列の正確なコピーが必要な理由がわかりませんか?

たとえば、2番目の場合:

SQL> CREATE TABLE R_SEQUENCES_COUNT1
  2    (
  3      DS_ID NUMBER,
  4      LINE_TIME TIMESTAMP(6),
  5      DAY_ID  DATE GENERATED ALWAYS   AS (TRUNC(LINE_TIME)),
  6      HOUR_ID  DATE GENERATED ALWAYS  AS (TRUNC(LINE_TIME,'HH24')) ,
  7      MINUTE_ID DATE GENERATED ALWAYS AS (TRUNC(LINE_TIME,'MI')) ,
  8      SECOND_ID TIMESTAMP GENERATED ALWAYS AS (LINE_TIME+numtodsinterval(0, 'day')),
  9      R_ID       NUMBER,
 10      SEQUENCE_ID NUMBER
 11    )NOLOGGING
 12  /

Table created.

SQL> insert into  R_SEQUENCES_COUNT1 (ds_id, line_time) values (1, systimestamp);

1 row created.

SQL> @print_Table "select * from  R_SEQUENCES_COUNT1"
DS_ID                         : 1
LINE_TIME                     : 14-mar-2013 09:56:31.104921
DAY_ID                        : 14-mar-2013 00:00:00
HOUR_ID                       : 14-mar-2013 09:00:00
MINUTE_ID                     : 14-mar-2013 09:56:00
SECOND_ID                     : 14-mar-2013 09:56:31.104921
R_ID                          :
SEQUENCE_ID                   :
-----------------
于 2013-03-14T08:25:31.133 に答える