我创建了下表:
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE "MY2XSYEHT" (
pKy NUMBER(19, 0) PRIMARY KEY AUTOINCREMENT,
cTm NUMBER(19, 0), uTm NUMBER(19, 0), oTm NUMBER(19, 0), eTm NUMBER(19, 0),
oID VARCHAR2(32), kID VARCHAR2(32), idx NUMBER(3,0), typ NUMBER(3,0),
nVl FLOAT(24), sVl VARCHAR2(64), tVl VARCHAR2(4000) )';
EXCEPTION WHEN OTHERS THEN
IF SQLCODE != -955 THEN RAISE;
END IF;
END;
然后在主键上创建了一个序列和触发器:
CREATE SEQUENCE "MY2XSYEHT_SEQ" START WITH 1001 INCREMENT BY 1 CACHE 10
CREATE OR REPLACE TRIGGER "MY2XSYEHT_TRIGGER"
BEFORE INSERT ON "MY2XSYEHT"
FOR EACH ROW
DECLARE
BEGIN
IF( :NEW.pKy IS NULL ) THEN
:NEW.pKy := "MY2XSYEHT_SEQ".nextval
END IF;
END;
执行以下 MERGE 语句时,我收到“ORA-00947:没有足够的值”
MERGE INTO "MY2XSYEHT" destTable
USING (SELECT ? oID, ? kID, ? idx, ? typ, ? nVl, ? sVl, ? tVl FROM DUAL) srcTable
ON (destTable.oID=srcTable.oID
and destTable.kID=srcTable.kID
and destTable.idx=srcTable.idx)
WHEN MATCHED THEN UPDATE SET destTable.typ=srcTable.typ,
destTable.nVl=srcTable.nVl,
destTable.sVl=srcTable.sVl,
destTable.tVl=srcTable.tVl
WHEN NOT MATCHED THEN INSERT VALUES (srcTable.oID, srcTable.kID, srcTable.idx,
srcTable.typ, srcTable.nVl, srcTable.sVl, srcTable.tVl)