Warm tip: This article is reproduced from stackoverflow.com, please click
oracle-sqldeveloper plsql

Procedure PL/SQL without parameters

发布于 2020-04-18 10:12:10

I want to create a procedure without parameters (In SQL DEVELOPER) but I am not sure how to do it, I have tried it in the following way and it sends me an error in "Num1 NUMBER";

create or replace package PK_MAC as
      PROCEDURE PR_PRUEBAS 
      IS
      Num1 NUMBER;
      BEGIN
      Num1 := 2;
      end;
  end;
Questioner
Myke Andres
Viewed
36
thatjeffsmith 2020-02-05 02:41

You're trying to create a procedure or a package, with a procedure?

Here is a working example of what you're doing, as a package.

Your package will have two parts, a SPEC and a BODY.

The SPEC will publicly share the definition of the procedure and the variable, NUM1.

The BODY will define what the procedure actually does. Since NUM1 is defined already in the context of the package in the spec, I can use it in my procedure in the body.

create or replace package PK_MAC as
      num1 integer;
      PROCEDURE PR_PRUEBAS; 

  end;
/

create or replace package body PK_MAC IS
 procedure pr_pruebas is
  BEGIN
      Num1 := 2;
  end pr_pruebas;
end PK_MAC;
/