简体   繁体   English

编译程序时出错

[英]Getting error while compiling the procedure

I have declared a array inside the procedure.我在程序中声明了一个数组。 When i write create or replace PROCEDURE myprocedure , its gets compiled but when i write procedure myprocedure it gives the below error.I have to keep this inside a pl sql package.当我编写 create 或 replace PROCEDURE myprocedure 时,它​​会被编译,但是当我编写程序 myprocedure 时,它​​会出现以下错误。我必须将其保存在 pl sql 包中。 I am new to procedure .我是程序的新手。 Please help.请帮忙。

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;

error错误

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:

write procedure myprocedure it gives the below error.I have to keep this inside a pl sql package.编写程序 myprocedure 它给出了以下错误。我必须将它保存在 pl sql 包中。

Here is the package working fine for me:这是对我来说工作正常的包:

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;

Execution:执行:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM