×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

XXX

heihei, you are wrong, but I agree trigger is better.

From Oracle 8i Documentation:

Where to Use Sequence Values
You can use CURRVAL and NEXTVAL in:

The SELECT list of a SELECT statement that is not contained in a subquery, materialized view, or view

The SELECT list of a subquery in an INSERT statement

The VALUES clause of an INSERT statement

The SET clause of an UPDATE statement

Example 2
This example increments the employee sequence and uses its value for a new employee inserted into the employee table:

INSERT INTO emp
VALUES (empseq.nextval, 'LEWIS', 'CLERK',
7902, SYSDATE, 1200, NULL, 20);
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Help! In Oracle 8i, how to set the primary key column increase automatically (pls provide details)? if it's 'sequence', how to apply it to a table? thanks!
    • 我是新手。不知道对不对,你试试吧。
      SELECT SEED+1
      INTO vSeed
      FROM AUTOKEY
      WHERE TBNAME = 'yourtablename';
      用insert假如纪录。
      UPDATE AUTOKEY
      SET SEED= vSeed
      WHERE TBNAME = 'yourtablename';
      • 不规范....., 应该用 sequence
        • 同意!用sequence和trigger。每次建新表都很痛苦,怀念SQL Server的Identity......
        • 有什么差别?我正在用一个script加数据呢。
          • 需要手工lock table, 容易影响performance
    • 1. create sequence urName INCREMENT BY 1 START WITH SomeVal NOMAXVALUE 2. SELECT urName.NEXTVAL FROM DUAL 3. insert into ur_table(ID......) value ("the sequence you just had"......)
    • in
      CREATE SEQUENCE yourseqname
      START WITH yourstartnum
      MAXVALUE yourmaxnum
      INCREMENT BY yourincrementvalue ;

      insert into yourtablename(yourkeycolum)
      values(yourseqname.NEXTVAL);
      • X.
        seq.nextval cannot be used in update/insert.

        Trigger is better from performance issue.
        • XX
          seq.nextval works fine in update/insert
        • XXX
          heihei, you are wrong, but I agree trigger is better.

          From Oracle 8i Documentation:

          Where to Use Sequence Values
          You can use CURRVAL and NEXTVAL in:

          The SELECT list of a SELECT statement that is not contained in a subquery, materialized view, or view

          The SELECT list of a subquery in an INSERT statement

          The VALUES clause of an INSERT statement

          The SET clause of an UPDATE statement

          Example 2
          This example increments the employee sequence and uses its value for a new employee inserted into the employee table:

          INSERT INTO emp
          VALUES (empseq.nextval, 'LEWIS', 'CLERK',
          7902, SYSDATE, 1200, NULL, 20);
          • confirmed: Since 8i. u V me X.
    • Thank you all Oracle gurus! I'm a Java guy who is using Oracle DBA Studio on Win2k, Can you tell me how to implement all these steps? I can create a sequence, but how to do the next steps? thank you very much!!!
      • tooo...easy
        set identity=yes, identity seed=1; identiy increment=1 when you design the column
        • you're talking about MS SQL Server, not Oracle 8i, right? thx any way...
          • sorry, I didn't pay attention
            • ;p