oracle 如何在以(SEQUENCE_NO)为列的历史表中插入值

zte4gxcn  于 2023-10-16  发布在  Oracle
关注(0)|答案(2)|浏览(124)

我想要的是,在将数据插入主表时。我首先将其旧数据插入其历史表。历史表有更多的2列什么主表,这是HISTSEQ_NOHIST_DATE
所以,在插入我下面的代码时。我得到的错误是
ORA-00947:数值不足
那么,如何处理SEQUENCE部分呢?

string queryInsert;
        queryInsert = "insert into xxacl_pN_LEASES_ALL_h select sysdate, t.* from xxacl_pN_LEASES_ALL t";
        OracleConnection conInsert = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToString());
        OracleCommand cmd1 = new OracleCommand();
        string allQueries = queryInsert;
        cmd1.CommandText = allQueries;
        cmd1.Connection = conInsert;
        conInsert.Open();
        cmd1.ExecuteNonQuery();

表的脚本

CREATE TABLE XXCUS.XXACL_PN_LEASES_ALL_H
    (
      HISTSEQ_NO                   NUMBER           NOT NULL,
      HIST_DATE                    DATE             NOT NULL,
      MKEY                         NUMBER,
      LEASE_ID                     NUMBER,
      LAST_UPDATE_DATE             DATE             NOT NULL,
      LAST_UPDATED_BY              NUMBER           NOT NULL,
      CREATION_DATE                DATE             NOT NULL,
      CREATED_BY                   NUMBER           NOT NULL,
      LAST_UPDATE_LOGIN            NUMBER,
      LEASE_NUM                    VARCHAR2(30 BYTE) NOT NULL,
      PARENT_LEASE_ID              NUMBER,
      ADDRESS_LOCATION_ID          NUMBER,
      LEASE_TYPE_CODE              VARCHAR2(30 BYTE) NOT NULL,
      PAYMENT_TERM_PRORATION_RULE  NUMBER,
      ABSTRACTED_BY_USER           NUMBER           NOT NULL,
      COMMENTS                     VARCHAR2(240 BYTE),
      STATUS                       VARCHAR2(1 BYTE),
      ORG_ID                       NUMBER(15)       DEFAULT NULL,
      LEASE_CLASS_CODE             VARCHAR2(30 BYTE) NOT NULL,
      LEASE_STATUS                 VARCHAR2(30 BYTE) NOT NULL,
      CUSTOMER_ID                  NUMBER(15),
      DELETE_FLAG                  CHAR(1 BYTE),
      PROJECT_ID                   NUMBER,
      BUILDING_ID                  NUMBER,
      FLOOR_ID                     NUMBER,
      FLAT_ID                      NUMBER,
      CARPET_AREA                  VARCHAR2(30 BYTE),
      SALEABLE_AREA                VARCHAR2(30 BYTE),
      FLAT_TYPE                    VARCHAR2(30 BYTE),
      FLAT_STATUS                  VARCHAR2(30 BYTE),
      FLAT_SUBSTATUS               VARCHAR2(30 BYTE),
      CEF_MKEY                     NUMBER,
      BOOKING_NO                   NUMBER,
      ASSIGNED_TO                  NUMBER,
      APPROVER_LAVEL               NUMBER,
      PDC_TYPE                     VARCHAR2(30 BYTE),
      IS_MIGRATED                  CHAR(1 BYTE),
      SYS_CREATION_DATE            DATE,
      F_UPDATED_BY                 NUMBER,
      F_FOLLOWUP_DATE              DATE,
      F_ACTIVITY_ID                NUMBER,
      F_SUB_ACTIVITY_ID            NUMBER,
      F_FOLLOWUP_TYPE_ID           NUMBER,
      F_NEXT_FOLLOW_UP_DATE        DATE,
      F_NEXT_ACTIVITY_ID           NUMBER,
      F_NEXT_SUB_ACTIVITY_ID       NUMBER,
      F_REMARKS                    VARCHAR2(500 BYTE),
      F_FOLLOWUP_SR_NO             NUMBER,
      F_REASSIGN_REASON            NUMBER(10),
      USER_TYPE                    VARCHAR2(10 BYTE),
      LOCATION_ID                  NUMBER(10),
      F_LAST_UPDATE_DATE           DATE,
      F_TASK_ID                    NUMBER(10),
      F_TASK_SR_NO                 NUMBER(10),
      BOOKING_DATE                 DATE,
      INV_DATE                     DATE,
      LOAN_DETAILS                 VARCHAR2(10 BYTE),
      AUTO_GEN_BILLING             VARCHAR2(10 BYTE),
      ADF                          VARCHAR2(10 BYTE),
      SALES_USER_ID                NUMBER(10),
      PREDEFINED_CUST              CHAR(1 BYTE),
      SCHEME_ID                    NUMBER(10),
      LOCK_PERIOD                  NUMBER(10),
      NO_OF_DAYS                   NUMBER(10),
      TYPE_OF_BOOKING              VARCHAR2(10 BYTE),
      RENTFREE_PERIOD              DATE,
      FREE_NO_DAYS                 VARCHAR2(250 BYTE),
      LOI_DATE                     DATE
)
6ss1mwsb

6ss1mwsb1#

正如我所看到的,您已经为一个附加列HIST_DATE添加了值sysdate。现在需要为辅助列HISTSEQ_NO添加值。你有序列表xxacl_pN_LEASES_ALL_h或可能是你有另一个序列,你可以使用?
例如,如果你有序列my_seq,你可以在查询中使用它:

insert into xxacl_pN_LEASES_ALL_h 
    select 
        my_seq.nextval, sysdate, t.* 
    from 
        xxacl_pN_LEASES_ALL t

但请记住列的顺序

i2loujxw

i2loujxw2#

更改插入查询以包括要插入的字段(不包括自动增量值)

queryInsert = "insert into xxacl_pN_LEASES_ALL_h(<insert column names here>) select sysdate, t.* from xxacl_pN_LEASES_ALL t";

在这里,列名的顺序很重要。

相关问题