<small id='5jpcF'></small><noframes id='5jpcF'>

    <i id='5jpcF'><tr id='5jpcF'><dt id='5jpcF'><q id='5jpcF'><span id='5jpcF'><b id='5jpcF'><form id='5jpcF'><ins id='5jpcF'></ins><ul id='5jpcF'></ul><sub id='5jpcF'></sub></form><legend id='5jpcF'></legend><bdo id='5jpcF'><pre id='5jpcF'><center id='5jpcF'></center></pre></bdo></b><th id='5jpcF'></th></span></q></dt></tr></i><div id='5jpcF'><tfoot id='5jpcF'></tfoot><dl id='5jpcF'><fieldset id='5jpcF'></fieldset></dl></div>

    <tfoot id='5jpcF'></tfoot>
    <legend id='5jpcF'><style id='5jpcF'><dir id='5jpcF'><q id='5jpcF'></q></dir></style></legend>
    • <bdo id='5jpcF'></bdo><ul id='5jpcF'></ul>

      1. 在oracle中用sequence.nextval创建表

        create table with sequence.nextval in oracle(在oracle中用sequence.nextval创建表)

          1. <tfoot id='oB91w'></tfoot>
              <tbody id='oB91w'></tbody>

          2. <legend id='oB91w'><style id='oB91w'><dir id='oB91w'><q id='oB91w'></q></dir></style></legend>
              <bdo id='oB91w'></bdo><ul id='oB91w'></ul>

                <small id='oB91w'></small><noframes id='oB91w'>

                  <i id='oB91w'><tr id='oB91w'><dt id='oB91w'><q id='oB91w'><span id='oB91w'><b id='oB91w'><form id='oB91w'><ins id='oB91w'></ins><ul id='oB91w'></ul><sub id='oB91w'></sub></form><legend id='oB91w'></legend><bdo id='oB91w'><pre id='oB91w'><center id='oB91w'></center></pre></bdo></b><th id='oB91w'></th></span></q></dt></tr></i><div id='oB91w'><tfoot id='oB91w'></tfoot><dl id='oB91w'><fieldset id='oB91w'></fieldset></dl></div>
                • 本文介绍了在oracle中用sequence.nextval创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用以下查询创建了一个序列,

                  i created a sequence using the following query,

                  create sequence qname_id_seq start with 1 increment by 1 nocache;
                  

                  现在,当我尝试创建一个使用上述序列的表时,它抛出以下错误,

                  Now when i try to create a table which uses the above sequence, it is throwing the following error,

                  Error report:
                  SQL Error: ORA-00907: missing right parenthesis
                  00907. 00000 -  "missing right parenthesis"
                  

                  我使用以下查询创建了一个带有 sequence.nextval 的表,

                  I used the following query to create a table with sequence.nextval,

                  CREATE TABLE qname
                  (
                      qname_id integer NOT NULL default qname_id_seq.nextval PRIMARY KEY,
                      qname    VARCHAR2(4000) NOT NULL -- CONSTRAINT qname_uk UNIQUE
                  );
                  

                  推荐答案

                  Oracle 12c

                  我们现在终于像许多其他数据库一样拥有 IDENTITY 列,以防在幕后自动生成序列.可以看出,此解决方案比基于触发器的解决方案快得多 在这篇博文中.

                  Oracle 12c

                  We now finally have IDENTITY columns like many other databases, in case of which a sequence is auto-generated behind the scenes. This solution is much faster than a trigger-based one as can be seen in this blog post.

                  因此,您的表创建将如下所示:

                  So, your table creation would look like this:

                  CREATE TABLE qname
                  (
                      qname_id integer GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY,
                      qname    VARCHAR2(4000) NOT NULL -- CONSTRAINT qname_uk UNIQUE
                  );
                  

                  Oracle 11g 及以下

                  根据文档,您不能这样做:

                  对默认列值的限制 DEFAULT 表达式不能包含对 PL/SQL 函数或其他列、伪列 CURRVAL、NEXTVAL、LEVEL、PRIOR 和 ROWNUM 或未完全指定的日期常量的引用.

                  Restriction on Default Column Values A DEFAULT expression cannot contain references to PL/SQL functions or to other columns, the pseudocolumns CURRVAL, NEXTVAL, LEVEL, PRIOR, and ROWNUM, or date constants that are not fully specified.

                  在 Oracle 中具有自动增量"列的标准方法是使用触发器,例如

                  The standard way to have "auto increment" columns in Oracle is to use triggers, e.g.

                  CREATE OR REPLACE TRIGGER my_trigger
                    BEFORE INSERT 
                    ON qname
                    FOR EACH ROW
                    -- Optionally restrict this trigger to fire only when really needed
                    WHEN (new.qname_id is null)
                  DECLARE
                   v_id qname.qname_id%TYPE;
                  BEGIN
                    -- Select a new value from the sequence into a local variable. As David
                    -- commented, this step is optional. You can directly select into :new.qname_id
                    SELECT qname_id_seq.nextval INTO v_id FROM DUAL;
                  
                    -- :new references the record that you are about to insert into qname. Hence,
                    -- you can overwrite the value of :new.qname_id (qname.qname_id) with the value
                    -- obtained from your sequence, before inserting
                    :new.qname_id := v_id;
                  END my_trigger;
                  

                  在文档中详细了解Oracle TRIGGERs

                  这篇关于在oracle中用sequence.nextval创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Oracle PL/SQL - Raise User-Defined Exception With Custom SQLERRM(Oracle PL/SQL - 使用自定义 SQLERRM 引发用户定义的异常)
                  Oracle: is there a tool to trace queries, like Profiler for sql server?(Oracle:是否有跟踪查询的工具,例如用于 sql server 的 Profiler?)
                  SELECT INTO using Oracle(使用 Oracle SELECT INTO)
                  How to handle Day Light Saving in Oracle database(如何在 Oracle 数据库中处理夏令时)
                  PL/SQL - Use quot;Listquot; Variable in Where In Clause(PL/SQL - 使用“列表Where In 子句中的变量)
                  Oracle: Import CSV file(Oracle:导入 CSV 文件)

                    • <small id='EUhoA'></small><noframes id='EUhoA'>

                        <bdo id='EUhoA'></bdo><ul id='EUhoA'></ul>
                        <tfoot id='EUhoA'></tfoot>

                            <i id='EUhoA'><tr id='EUhoA'><dt id='EUhoA'><q id='EUhoA'><span id='EUhoA'><b id='EUhoA'><form id='EUhoA'><ins id='EUhoA'></ins><ul id='EUhoA'></ul><sub id='EUhoA'></sub></form><legend id='EUhoA'></legend><bdo id='EUhoA'><pre id='EUhoA'><center id='EUhoA'></center></pre></bdo></b><th id='EUhoA'></th></span></q></dt></tr></i><div id='EUhoA'><tfoot id='EUhoA'></tfoot><dl id='EUhoA'><fieldset id='EUhoA'></fieldset></dl></div>
                          1. <legend id='EUhoA'><style id='EUhoA'><dir id='EUhoA'><q id='EUhoA'></q></dir></style></legend>
                              <tbody id='EUhoA'></tbody>