Create a stored procedure without parameters in ORACLE

1

I am new to this database engine, I believe that I create a store procedure and when I create it, there is no problem, but when I run it I get this:

ORA-06550: line 2, column 3:
PLS-00905: object WEB_SEGURIDAD.SIMEXA_SP_DEPARTAMENTOS_UBIGEO is invalid
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored

My code is this:

CREATE OR REPLACE PROCEDURE "SIMEXA_SP_DEPARTAMENTOS_UBIGEO"
AS
       BEGIN
         SELECT DISTINCT dpto FROM up100.UBIGEO;
       END;

Calling the stored procedure:

BEGIN
  SIMEXA_SP_DEPARTAMENTOS_UBIGEO;
END;
    
asked by Gian Franco Alexis Poma Vidal 10.12.2018 в 22:57
source

1 answer

1

I will start my answer by saying that Oracle is not SQL Server , where I have seen this practice.

The closest thing, in my opinion, you can do in Oracle , is to return a RefCursor , which is basically a data set, but you can not simply execute one or more select statements and wait for the engine to collect the result and somehow < em> return it , as if it occurs in SQL Server .

The syntax, it would be something like this:

In SQL * Plus:

SQL> create procedure miProc (prc out sys_refcursor)
  2  is
  3  begin
  4     open prc for select * from emp;
  5  end;
  6  /

Procedure created.

SQL> var rc refcursor
SQL> execute miProc(:rc)

PL/SQL procedure successfully completed.

SQL> print rc

     EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ----------- ---------- ---------- ----------
      7839 KING       PRESIDENT            17-NOV-1981       4999                    10
      7698 BLAKE      MANAGER         7839 01-MAY-1981       2849                    30
      7782 CLARKE     MANAGER         7839 09-JUN-1981       2449                    10
      7566 JONES      MANAGER         7839 02-APR-1981       2974                    20
      7788 SCOTT      ANALYST         7566 09-DEC-1982       2999                    20
      7902 FORD       ANALYST         7566 03-DEC-1981       2999                    20
      7369 SMITHY     CLERK           7902 17-DEC-1980       9988         11         20
      7499 ALLEN      SALESMAN        7698 20-FEB-1981       1599       3009         30
      7521 WARDS      SALESMAN        7698 22-FEB-1981       1249        551         30
      7654 MARTIN     SALESMAN        7698 28-SEP-1981       1249       1400         30
      7844 TURNER     SALESMAN        7698 08-SEP-1981       1499          0         30
      7876 ADAMS      CLERK           7788 12-JAN-1983       1099                    20
      7900 JAMES      CLERK           7698 03-DEC-1981        949                    30
      7934 MILLER     CLERK           7782 23-JAN-1982       1299                    10
      6668 Umberto    CLERK           7566 11-JUN-2009      19999          0         10
      9567 ALLBRIGHT  ANALYST         7788 02-JUN-2009      76999         24         10

With this response from StackOverflow in English.

    
answered by 10.12.2018 / 23:31
source