Error: Cant create procedure with select in PL/SQL

Error: Cant create procedure with select in PL/SQL

我正在包中创建过程,我想做一个简单的 select 但我收到此错误。

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(6,3): PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: language "

包由其规格和主体组成。例如:

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.

测试:

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

PL/SQL procedure successfully completed.

SQL>

或者,在您的情况下:

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>

请注意 - 当您在 PL/SQL 中使用 select 语句时 - 您必须将结果 into 放入某些东西(例如变量,就像我在示例中所做的那样) .你不能只是 SELECT * FROM MAC ...