Domanda

I create a simple procedure in oracle 11g with the client squirrel, this s the code

create or replace procedure EXAMPLE_P is
begin
    1+2;
end;/

while executing i got this warning

Warning:   Warning: execution completed with warning
SQLState:  99999
ErrorCode: 17110
Position: 0

Query 1 of 1, Rows read: 0, Elapsed time (seconds) - Total: 0.031, SQL query: 0.031, Building output: 0

The problem here, i can't call my procedure.

begin
    EXAMPLE_P();
end;/

I got this error when i execute the block above.

Error: ORA-06550: line 2, column 9:
PLS-00302: component 'EXAMPLE_P' must be declared
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored

SQLState:  65000
ErrorCode: 6550
Position: 37

The procedure exists in the table ALL_OBJECTS with the status INVALID. I tried to compile it (validate the status) but i won't work with the query below

alter procedure EXAMPLE_P COMPILE;

SomeOne knows what i can do to call my procedure, (i used PL/SQL developer and never meet this problem)

È stato utile?

Soluzione

You can't call your procedure because you didn't create it. You didn't create it because you had no assignment target for 1 + 2. You have to declare a variable to put this in. You also have the / in the wrong place.

Compare the differences between these two:

SQL> create or replace procedure EXAMPLE_P is
  2  begin
  3      1+2;
  4  end;/
  5  /

Warning: Procedure created with compilation errors.

SQL> create or replace procedure EXAMPLE_P is
  2    i number; -- Declare a variable
  3  begin
  4      i := 1 + 2; -- assign something to the variable.
  5  end;
  6  /

Procedure created.

You are then calling it incorrectly. If you have no parameters then you shouldn't include the ().

SQL> begin
  2     example_p;
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL>

I tried to create your procedure in PL/SQL developer and got the following error; so, I'm a little surprised that you never had a problem.

Compilation errors for PROCEDURE ALERT.EXAMPLE_P

Error: PLS-00103: Encountered the symbol "1" when expecting one of the following:

   ( begin case declare exit for goto if loop mod null pragma
   raise return select update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   continue close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe purge
The symbol "return" was substituted for "1" to continue. Line: 3 Text: 1 + 2;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top