重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 936|回复: 0
打印 上一主题 下一主题

[Oracle] ORA-1722 Error Creating a Sequence

[复制链接]
跳转到指定楼层
楼主
发表于 2024-9-29 14:55:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
现象:
========

You are trying to create a sequence starting with a value one greater
than a value found in an existing column of a table.  This column contains
some unknown maximum number.  You keep getting the following error:

  ORA-01722: invalid number


例子:
--------

SQL> create sequence testusers start with (max(UNIQUEFIELD) + 1)
     from users;
create sequence testusers start with (max(UNIQUEFIELD) + 1)
                       *
ERROR at line1:
ORA-01722: invalid number


处理方法:
=========

There are two solutions to this problem:

o  Determine the maximum value of the table column and then
   supply it to the CREATE SEQUENCE statement:

   SQL> select max(deptno+1) from <TABLE_NAME>

   MAX(DEPTNO+1)
   -------------
              41

   SQL> create sequence test1 start with 41;

or,

o  Use a PL/SQL script with EXECUTE IMMEDIATE to create the sequence:

    DECLARE
      v_num   NUMBER(10);
      bar     VARCHAR2(100);
    BEGIN
      SELECT max(deptno+1)
      INTO v_num
      FROM <USERNAME>.<TABLE_NAME>
      bar := 'CREATE SEQUENCE test1 START WITH '||v_num;
      execute immediate bar;
    END;
    /


解释:
============

This SQL statement always returns an ORA-1722 error because the
syntax for CREATE SEQUENCE is expecting an INTEGER when using the
START WITH clause.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-12-21 21:47 , Processed in 0.113701 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表