将序列号插入Oracle PL / SQL数据库

时间:2013-06-17 10:13:56

标签: for-loop plsql oracle10g

我正在尝试将一系列数字插入到数据库中。这是我的代码但不起作用:

DECLARE 
  j number(10) ;
BEGIN
  FOR j IN 1001020930..1001021930
  LOOP
    INSERT INTO PROD.issue_id(j,'NEW',null)
  END LOOP;
END;

表格结构:

VARCHAR2 (128 BYTE)
VARCHAR2 (10 BYTE)
DATE

这是错误代码:

Error starting at line 1 in command:
DECLARE 
  j number(10) ;
BEGIN
  FOR j IN 1001020930..1001021930
  LOOP
    INSERT INTO PROD.issue_id(j,'NEW',null)
  END LOOP;
END;
Error report:
ORA-06550: line 6, column 42:
PL/SQL: ORA-01747: invalid user.table.column, table.column, or column specification
ORA-06550: line 6, column 5:
PL/SQL: SQL Statement ignored
ORA-06550: line 8, column 4:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

   loop
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

我不明白这些错误,因为我对PL / SQL

很新

1 个答案:

答案 0 :(得分:3)

您在insert语句中错过了values命令,而没有用分号终止插入语句。

做为

    DECLARE
    j    NUMBER (10);
BEGIN
    FOR j IN 1001020930 .. 1001021930
    LOOP
        INSERT INTO   issue_id
              VALUES   (j, 'NEW', SYSDATE);
    END LOOP;
END;