0

I am creating a procedure in a package and I want to make a simple select but I get this error.

create or replace PACKAGE PK_MAC AS
   /* TODO enter package declarations (types, exceptions, methods etc) here */ 
    PROCEDURE PR_PRUEBAS (
        IDNUM NUMBER := 0, 
        NOMBRES VARCHAR2 := 'Usuario', 
        FECHANACIMIENTO DATE := SYSDATE, 
        ARCHIVOS CLOB := ''
    )
    IS
    BEGIN
        SELECT * FROM MAC;
    END;
END;

Error:

Error(6,3): PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: language "

GMB
  • 216,147
  • 25
  • 84
  • 135
  • 1
    A "simple `SELECT` statement" is not a valid statement in a PL/SQL procedure. Simple as that. This is quite apart from the higher-level error, which is that the procedure code belongs in the package **body**; the package *declaration* (the `CREATE OR REPLACE PACKAGE` statement) only declares the procedure, including its parameters and their data types, etc. - but it cannot contain the procedure code (from `BEGIN` to `END`) - that **must** be in the package body. –  Feb 04 '20 at 00:50

1 Answers1

2

Package consists of its specification and body. For example:

SQL> create or replace package pk_mac as
  2    procedure pr_pruebas (p_idnum in number);
  3  end;
  4  /

Package created.

SQL> create or replace package body pk_mac as
  2    procedure pr_pruebas (p_idnum in number)
  3    is
  4      l_ename emp.ename%type;
  5    begin
  6      select ename
  7      into l_ename
  8      from emp
  9      where empno = p_idnum;
 10
 11      dbms_output.put_line(l_ename);
 12    end;
 13  end;
 14  /

Package body created.

Testing:

SQL> set serveroutput on
SQL>
SQL> exec pk_mac.pr_pruebas(7654);
MARTIN

PL/SQL procedure successfully completed.

SQL>

Or, in your case:

SQL> create or replace PACKAGE PK_MAC AS
  2    PROCEDURE PR_PRUEBAS
  3      (IDNUM NUMBER := 0,
  4       NOMBRES VARCHAR2 := 'Usuario',
  5       FECHANACIMIENTO DATE := SYSDATE,
  6       ARCHIVOS CLOB := '');
  7  end;
  8  /

Package created.

SQL>
SQL> create or replace PACKAGE body PK_MAC AS
  2    PROCEDURE PR_PRUEBAS
  3      (IDNUM NUMBER := 0,
  4       NOMBRES VARCHAR2 := 'Usuario',
  5       FECHANACIMIENTO DATE := SYSDATE,
  6       ARCHIVOS CLOB := '')
  7    is
  8    begin
  9      null;
 10    end;
 11  end;
 12  /

Package body created.

SQL>

Note that - when you use a select statement in PL/SQL - you have to put the result into something (such as a variable, like I did in my example). You can't just SELECT * FROM MAC ...

Littlefoot
  • 131,892
  • 15
  • 35
  • 57