编译过程时出错

时间:2017-10-05 12:00:31

标签: oracle stored-procedures plsql

我在程序中声明了一个数组。当我编写创建或替换PROCEDURE myprocedure时,它会被编译,但是当我编写过程myprocedure时,它会给出以下错误。我必须将它保存在pl sql包中。我是程序新手。请帮忙。

PROCEDURE myprocedure
IS

   type namesarray IS VARRAY(5) OF VARCHAR2(10); 
   type grades IS VARRAY(5) OF INTEGER; 
   names namesarray; 
   marks grades;
   total integer; 
BEGIN 
   names := namesarray('Kavita', 'Pritam', 'Ayan', 'Rishav', 'Aziz'); 
   marks:= grades(98, 97, 78, 87, 92); 
   total := names.count; 
   dbms_output.put_line('Total '|| total || ' Students'); 
   FOR i in 1 .. total LOOP 
      dbms_output.put_line('Student: ' || names(i) || ' 
      Marks: ' || marks(i)); 
   END LOOP; 
END;

错误

RA-06550: line 2, column 4:
PLS-00201: identifier 'NAMES' must be declared
ORA-06550: line 2, column 4:
PL/SQL: Statement ignored
ORA-06550: line 3, column 4:
PLS-00201: identifier 'MARKS' must be declared
ORA-06550: line 3, column 4:
PL/SQL: Statement ignored
ORA-06550: line 4, column 4:
PLS-00201: identifier 'TOTAL' must be declared
ORA-06550: line 4, column 4:
PL/SQL: Statement ignored
ORA-06550: line 5, column 36:
PLS-00201: identifier 'TOTAL' must be declared
ORA-06550: line 5, column 4:
PL/SQL: Statement ignored
ORA-06550: line 6, column 18:
PLS-00201: identifier 'TOTAL' must be declared
ORA-06550: line 6, column 4:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

1 个答案:

答案 0 :(得分:1)

  

写程序myprocedure它给出了以下错误。我必须保留   这个在pl sql包里面。

以下是适合我的套餐:

CREATE OR REPLACE PACKAGE my_test
AS
   PROCEDURE myprocedure;
END;
/
CREATE OR REPLACE PACKAGE BODY my_test
AS
   PROCEDURE myprocedure
   IS
      TYPE namesarray IS VARRAY (5) OF VARCHAR2 (10);

      TYPE grades IS VARRAY (5) OF INTEGER;

      names   namesarray;
      marks   grades;
      total   INTEGER;
   BEGIN
      names :=
         namesarray ('Kavita',
                     'Pritam',
                     'Ayan',
                     'Rishav',
                     'Aziz');
      marks :=
         grades (98,
                 97,
                 78,
                 87,
                 92);

      --total := names.COUNT;
      DBMS_OUTPUT.put_line ('Total ' || names.COUNT || ' Students');

      FOR i IN 1 .. names.COUNT
      LOOP
         DBMS_OUTPUT.put_line (
            'Student: ' || names (i) || '  Marks: ' || marks (i));
      END LOOP;
   END;
END;

执行:

SQL> EXEC my_test.MYPROCEDURE;
Total 5 Students
Student: Kavita  Marks: 98
Student: Pritam  Marks: 97
Student: Ayan  Marks: 78
Student: Rishav  Marks: 87
Student: Aziz  Marks: 92

PL/SQL procedure successfully completed.