是否可以在 Teradata 中创建虚拟列,即基于同一张表的其他列的值的列,例如:
CREATE SET TABLE TEST.ZZ_RECEIPTS,
NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
ID_RECEIPT NUMBER,
ID_ITEM NUMBER,
NUM_ITEM NUMBER,
VALUE_ITEM DECIMAL (10, 2)
/*,
-- TOTAL_ITEM is the virtual column I want to add
TOTAL_ITEM DECIMAL (10, 2) AS (NUM_ITEM * VALUE_ITEM)
*/
) PRIMARY INDEX (ID_RECEIPT, ID_ITEM);
INSERT INTO TEST.ZZ_RECEIPTS (ID_RECEIPT, ID_ITEM, NUM_ITEM, VALUE_ITEM) VALUES (1, 1, 3, 4.50); --3*4,50 = 13,50
INSERT INTO TEST.ZZ_RECEIPTS (ID_RECEIPT, ID_ITEM, NUM_ITEM, VALUE_ITEM) VALUES (1, 2, 4, 5.50); --4*5,50 = 22
COMMIT;
SELECT * FROM TEST.ZZ_RECEIPTS;
ID_RECEIPT ID_ITEM NUM_ITEM VALUE_ITEM TOTAL_ITEM
---------- ---------- ---------- ------------ ----------
1 1 3 4,50 13,5
1 2 4 5,50 22
编辑:我想在这个字段上创建一个索引,类似于基于函数的索引。
谢谢!