在使用DBUnit将数据导出到Oracle时,如何使用Oracle Sequences为表自动生成主键?
答案 0 :(得分:3)
我有同样的问题,但没有找到任何答案。我最终使用触发器自动生成技术密钥,如本文create table with sequence.nextval in oracle
中所述CREATE OR REPLACE TRIGGER ticketSequenceTrigger
BEFORE INSERT
ON TICKET
FOR EACH ROW
WHEN (new.id IS null)
DECLARE
v_id TICKET.id%TYPE;
BEGIN
SELECT TICKET_ID_SEQ.nextval INTO v_id FROM DUAL;
:new.id := v_id;
END ticketSequenceTrigger;
然后我简单地省略初始和预期数据集中的id列:
<ticket title="Ticket 1"
description="Description for ticket 1"
status="NEW"
created_date="2013-07-01 12:00:00"/>