ORA-00913錯誤:PL/SQL: ORA-00913: too many values

來源:互聯網
上載者:User

ORA-00913錯誤


描述:PL/SQL: ORA-00913: too many values


目標:編寫一個可以迴圈插入資料的指令碼


操作過程:SQL> desc tcustmer
Name               Null?    Type
 ----------------- -------- ----------------------------
 CUST_CODE         NOT NULL VARCHAR2(10)
 NAME                       VARCHAR2(30)
 CITY                       VARCHAR2(20)
 STATE                      CHAR(2)


SQL>CREATE SEQUENCE tcustmer_cust 
      INCREMENT BY 1
      START WITH 1
      MAXVALUE 100000000
      CACHE 10000
      NOCYCLE; 
      
SQL> begin
  2       for i in 1..10 loop
  3         insert into tcustmer
  4         values (tcustmer_cust.nextval,'T','test'||i,'BEIJING','CN');
  5         if mod(i,10)=0 then 
  6         commit;
  7         end if;
  8      end loop;
  9      commit;
 10  end;
 11  /
       insert into tcustmer
                   *
ERROR at line 3:
ORA-06550: line 3, column 20:
PL/SQL: ORA-00913: too many values
ORA-06550: line 3, column 8:
PL/SQL: SQL Statement ignored


檢查發現插入的values值,列數超過了tcustmer表的列數
調整如下:
SQL>begin
     for i in 1..10 loop
       insert into tcustmer
       values ('T'||tcustmer_cust.nextval,'test'||i,'BEIJING','CN');
       if mod(i,10)=0 then 
       commit;
       end if;
    end loop;
    commit;
end;
/
PL/SQL procedure successfully completed.
總結:

    對於tcustmer_cust.nextval理解錯誤,建立序列的目的正是消除主鍵的幹擾,所以在使用的時候需要將其放到列值中。



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.