Procedure created with compilation errors - stored-procedures

Below is the procedure I have created. When I execute it I'm getting "Procedure created with compilation errors" I don't understand where I did mistake in below procedure code, someone help me by finding error in the code
create or replace PROCEDURE newprocedur(inMerid IN VARCHAR2,outCount OUT NUMBER) AS
CURSOR c1 IS
select CLIENT_COUNT
from OP_TMER_CONF_PARENT
where MER_ID = inMerid
FOR UPDATE OF CLIENT_COUNT;
BEGIN
Open c1
loop
fetch c1 into outCount;
exit when c1%NOTFOUND;
outCount:=outCount+1;
update OP_TMER_CONF_PARENT
set CLIENT_COUNT = outCount
where current of c1;
end loop;
close c1;
END;
Thanks in advance

1- check for errors and see where error is
See here
2- You missed a semicolon in 5th line-
should be
Open c1;

In SQL*Plus you can use the command
show errors
to show you the errors in the PL/SQL code that was just compiled. See http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12041.htm
I'm not familiar with PL/SQL Developer, but TOAD does this automatically and show you the errors allowing you to quickly jump to the line(s) containing the error(s).

Related

Reference cursor in Oracle Sql Developer

I need to write a reference cursor in Oracle SQL developer and I have no clue how its written. I just know basic queries.
I have written following cursor to best of my knowledge after looking up into various example. I am getting an compile error "Missing or Invalid option".
Can anyone help me out?
Step 1: I created a new procedure in Oracle sql developer version 4.
Step 2: I wrote the following cursor
DECLARE
routeid VARCHAR2(10);
cursor c1 IS
SELECT shipment_id FROM SHIPMENT
WHERE shipment_id = 20;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO routeid;
EXIT WHEN c1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(routeid);
END LOOP;
END;
/
Thank you in advance for the help.
Better way to do simple cursor
CREATE OR REPLACE PROCEDURE Test_cursor (Out_Pid OUT VARCHAR2) AS
cursor c1 IS
SELECT shipment_id,p_id FROM test
WHERE shipment_id = 99;
c1_rec c1%rowtype;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO c1_rec;
EXIT WHEN c1%NOTFOUND;
Out_Pid := c1_rec.p_id;
DBMS_OUTPUT.PUT_LINE('Result from query '||c1_rec.p_id );
DBMS_OUTPUT.PUT_LINE('Result from out parameter '||Out_Pid );
END LOOP;
END Test_cursor;

While executing simple stored procedure getting warning compiled but compilation error how to see

While executing a simple stored procedure getting a warning compiled but compilation error how to see.
Below is the query:
create procedure spgetdat
as
begin
select empis empname, empadd from tb1employees;
end;
While executing above query getting an error. Pls suggest what needs to be corrected.
Regards
Jitendra
Your Select statement inside the procedure is not correct. There should be into clause in the select statement inside the PL/SQL block.
It can be like below. You have to put a where condition for selection of one record or for best practice you can use cursor to fetch more then one record also.
create procedure spgetdat
as
v_empis tab1employees.empis%type;
v_empadd tab1employees.empadd%type;
begin
select empis empname ,empadd into v_empis,v_empadd from tb1employees where empis = 'given name' ;
end;
show errors;

PL SQL Procedure warning compiled Error PLS-00103

I'm starting with PL/SQL, this is my first Procedure and I find it difficult to compile; I have tried so many different versions, I carry the last attempt. I don't understand why SQLDEVELOPER say me: "procedure compiled (with errors)".
The compiler say me:" Errore(10,1): PLS-00103: Trovato il simbolo (find) "DECLARE" instead: begin function pragma procedure subtype type current cursor delete exists prior "
If there are other errors (also logical) please tell me. I would like to improve.
Thank you all for the answers
My Procedure:
create or replace PROCEDURE calcola_giorn (giornata IN INTEGER) is
-- si tenga presente che in realtà giornata=idPartita
somma NUMBER;
idcal NUMBER;
nometorn VARCHAR2;
idformaz NUMBER;
nomesquadr VARCHAR2;
DECLARE;
SELECT idcalendario INTO idcal FROM partita WHERE id= giornata;
SELECT nometorneo INTO nometorn FROM calendario WHERE id= idcal;
CURSOR formazioni_di_giornata IS
SELECT id, nomesquadra FROM formazione where idpartita= giornata;
CURSOR giocatori_di_giornata IS
SELECT votogiocatore FROM schiera WHERE idformazione= idformaz;
Begin
OPEN formazioni_di_giornata;
FOR tupla_formazione IN formazioni_di_giornata LOOP
somma:=0;
FETCH formazioni_di_giornata INTO idformaz, nomesquadr;
OPEN giocatori_di_giornata;
FOR tupla_giocatore IN giocatori_di_giornata LOOP
somma:= somma + tupla_giocatore.votogiocatore;
END LOOP;
CLOSE giocatori_di_giornata;
UPDATE partecipa SET punti= somma WHERE ( (nomesquadra= nomesquadr) AND (nometorneo= nometorn));
END LOOP;
CLOSE formazioni_di_giornata;
EXCEPTION WHEN OTHERS THEN raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END calcola_giorn;
Varchar limit should be defined, like varchar2(100)
Replace DECLARE; with BEGIN
All your cursors should go before BEGIN
Put END; for the procedure
You can try compiling after making these changes.

Calling an oracle stored procedure form COGNOS

In this link IBM they explain how to use an Oracle stored procedure with COGNOS.
They are doing :
create or replace package body project_pk as
procedure project_sp (tproj IN numeric, result1 in out project_type1) is
begin
open result1 for
select projects.projectid, projects.projecttype
from projects
where projects.projecttype=tproj;
end;
end;
/
With open result1 for they are opening the cursor explicitly. But, they do not seem to close it. Why is this?
You must return resuly set to Cognos. If you close the cursor then there are nor reuslts, right?
It's Cognos responsibility to close the cursor, once it finishes to pull the data from the SP.
In order to make you 100% sure that this is the case look at this link (totaly unrelated to Cognos):
Returning result Sets from SQL Server and Oracle
However, the sample you gave in your link, looks quite complex. Here is what I am using:
CREATE OR REPLACE PROCEDURE "COGNOS_SP" (
case_id in numeric,
po_refcur out sys_refcursor) is
BEGIN
open po_refcur for
select * FROM CASES WHERE CASE_ID = case_id;
END COGNOS_SP;

Simple Oracle Stored Procedure getting Invalid object error

I am trying to write a simple Oracle Stored Procedure:
CREATE OR REPLACE PROCEDURE act.skeleton
IS
DECLARE
v_rowCount NUMBER;
BEGIN
SELECT COUNT(1) INTO v_rowCount FROM ex.emp;
DBMS_OUTPUT.PUT_LINE(v_rowCount);
END;
However, when I try & run the procedure by issuing execute act.skeleton in PL/SQL Developer command window, I get the following error message:
ORA-06550: line 1, column 11:
PLS-00905: object ACT.SKELETON is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I tried to just run the code without the create procedure statement & it runs successfully with the output being displayed. I have tried both CREATE OR REPLACE PROCEDURE IS & CREATE OR REPLACE PROCEDURE AS options but I still get the same error.
I am not sure if this has anything to do with authorization or visibility of the procedure when I try and execute it or what is causing the act.skeleton object to be invalid. I looked into what the error means & it seems it usually refers to compilation error in the procedure but since I can run the code sans the procedure declaration, I am guessing the declaration piece is the culprit. I just don't know enough to figure out what is causing this and I was hoping that someone will be able to shed some more light on it and point me in the right direction
Thanks,
Ashish
Other Details:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
Don't use the DECLARE keyword in a stored procedure declaration. Remove that and it should compile.

Resources