【问题标题】:Oracle Identity Column cyclingOracle 身份列循环
【发布时间】:2019-12-18 06:14:58
【问题描述】:

我可以定义此 IDENT_COL 以通过其他列的值从最小值开始吗?

即如果 tx_ref 相同,则将 IDENT_COL.currentval 加 1,否则从 1 开始。

CREATE TABLE ogun_test(
    col_a       VARCHAR2(10),
    col_b       VARCHAR2(10),
    tx_ref      VARCHAR2(20),
    ident_col   NUMBER(*,0)
                            GENERATED BY DEFAULT AS IDENTITY
)

【问题讨论】:

  • 我认为你必须使用触发器

标签: oracle cycle identity-column


【解决方案1】:

你可以定义一个循环的身份:

create table t (
  c1 int
    generated as identity
    start with 1 cycle maxvalue 2
    nocache,
  c2 int
);

insert into t values ( default, 0 );
insert into t values ( default, 0 );
insert into t values ( default, 0 );

select * from t;

C1     C2   
    1     0 
    2     0 
    1     0 

但不是就其他列而言。所以你必须使用其他解决方案。

【讨论】:

  • 谢谢你,克里斯,在我放手尝试其他方法之前,我想确保自己没有错过任何一点:)
猜你喜欢
  • 2019-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多