Procedure created with compilation errors , not getting help in it - oracle

CREATE OR REPLACE PROCEDURE fetch( data OUT SYS_REFCURSOR)
AS
BEGIN
OPEN data FOR SELECT * FROM user_errors;
END;
/
Procedure created with compilation errors.
i tried but not getting why i am getting error like this , even in many example on internet i follow same but not get help
Oracle 19c version

FETCH is a reserved word in PL/SQL. Use another name for your stored procedure.
You are shown errors with
select * from user_errors;
In your case you are getting:
NAME
TYPE
SEQUENCE
LINE
POSITION
TEXT
ATTRIBUTE
MESSAGE_NUMBER
FETCH
PROCEDURE
1
1
11
PLS-00103: Encountered the symbol "FETCH" when expecting one of the following: current delete exists prior
ERROR
103
When compiling the package with another name, you'll get another error :-) Because CURSOR is no data type. Use SYS_REFCURSOR instead.
Demo: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=33d92c7ed3d254f672affd57bd66dbdd

Related

PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; - Not sure what is wrong in code

I am trying to create trigger as below but getting error specified below. Can any one please help me to figure out what is wrong with the code. Thank you in advance
Code:
CREATE OR REPLACE EDITIONABLE TRIGGER TEST_DATA.IVR_SEQ
BEFORE INSERT ON TEST_DATA.TRANSACTION
FOR EACH ROW
BEGIN
SELECT TEST_DATA.IVR_SEQ.NEXTVAL
INTO :new.IVRID
FROM dual;
END;
/
Error:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ;
Tool: Oracle SQL Developer
Strange, as there's nothing wrong with it, but I get the same error as you do when executing it literally.
SQL> create or replace -- EDITIONABLE
2 trigger scott.trg_ivr_seq
3 before insert on scott.transaction
4 for each row
5 begin
6 select scott.ivr_seq.nextval
7 into :new.ivrid
8 from dual;
Warning: Trigger created with compilation errors.
SQL> show err trigger trg_ivr_Seq
Errors for TRIGGER TRG_IVR_SEQ:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/11 PLS-00103: Encountered the symbol "end-of-file" when expecting
one of the following:
;
(editionable is not an option in my 11gXE so I removed it).
As you can see, error points to line #4, column #11 which is
4 for each row
Rewritten from scratch (and "improved" a little bit):
SQL> create or replace trigger scott.ivr_seq
2 before insert on scott.transaction
3 for each row
4 begin
5 :new.ivrid := scott.ivr_seq.nextval;
6 end;
7 /
Trigger created.
SQL>
It works with select as well (just that you wouldn't think that it is wrong):
SQL> create or replace trigger scott.ivr_seq
2 before insert on scott.transaction
3 for each row
4 begin
5 select scott.ivr_seq.nextval
6 into :new.ivrid
7 from dual;
8 end;
9 /
Trigger created.
SQL>
So ... rewrite it. I don't see any garbage characters (in Notepad++), I have no idea what's wrong with it.
[EDIT]
Luke Woodward's comment made me do another test. Yes, Luke is right!
Comment in the 1st line, before actually stating what I'm creating causes an error:
SQL> create or replace -- comment
2 trigger trg_test
3 before insert on dept
4 for each row
5 begin
6 null;
Warning: Trigger created with compilation errors.
But, comment in the 1st line AFTER stating what's being created doesn't cause any errors:
SQL> create or replace trigger -- comment here
2 trg_test
3 before insert on dept
4 for each row
5 begin
6 null;
7 end;
8 /
Trigger created.
Thank you, Luke!
There are several ways you can get this error:
Your SQL is malformed, you are missing a ; somewhere
Not present in the provided snippet.
Your SQL is malformed, the parser is being tripped up and believes things to be things they are not, finally failing when it get to the end of the file.
Not obviously present in the provided snippet. However i can't test the EDITIONABLE clause as it is not present in my db version, so it may be introducing some addition required syntax.
Your interface is mangling the SQL before it sends it to the database to be compiled.
Unlikely as SQL developer is way better at not doing this than SQL*Plus was, but if you have any custom configuration there are all kinds of things that could be happening, check what is actually getting to the database by looking at trigger in the database and see if it matches what you expect to be there.
Invalid characters in your code
Not a common issue but can be eliminated by either retyping the trigger manually, not using copy paste, or by pasting from a know clean source. (copy/paste from the web can include lots of weird character replacements used to get the layout right in the browser (no-break spaces, etc.), and apps like word can mangle things like quotes (e.g.Word replaces ' ' with ‘ ’)
Code in the same file before the trigger definition that has errors.
I am assuming you have run this separately from any other code, but if not put this trigger create statement in its own file and run it there.
Scenario 2 is being triggered by a non obvious misparse of the code.
This could be caused by other objects in this or a different schema with identical names, keyword use, etc. and can depend on which schema is running the DDL statement.
Try quoting TEST_DATA.TRANSACTION as TEST_DATA."TRANSACTION", TRANSACTION is a keyword in oracle, and while some keywords can be used in some contexts, possibly your version of oracle is treating it as a keyword and messing up the rest of the parsing. This compiles fine on my DB without the quotes so i would lean more toward the next possibility, but I have this issue with a schema named "SEARCH" on my database, in some contexts you need to quote the name to prevent compile errors.
Check for name reuse on schemas, tables, views, etc. In your example your trigger and your sequence have the same name TEST_DATA.IVR_SEQ. On its own this is not an issue, but can cause seemingly random compile errors depending on where the duplication is.
I could not reproduce your specific compile error, but I was able to create a few different compile errors by creating different name collisions (example creating a table in the TEST_DATA schema named TEST_DATA, creating a function named TEST_DATA, creating a package, sequence named TEST_DATA, a function named IVR_SEQ in a package named TEST_DATA, etc.). It is possible on your version of Oracle this or a similar collision is creating the EOF error.

how to trouble shoot when failed to run stored procedure in oracle sql developer?

I ran a stored procedure in oracle sql developer, and got following message
Connecting to the database QAV41PRODO.
Process exited.
Disconnecting from the database QAV41PRODO
when I debug it, I get the following messages:
*Connecting to the database SAMPLEDB.
Executing PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '111.111.111.111', '11111' )
Debugger accepted connection from database on port 11111.
Source breakpoint: EMP_SEL.pls:1
Source breakpoint: EMP_SEL.pls:5
Source breakpoint: EMP_SEL.pls:6
Executing PL/SQL: CALL DBMS_DEBUG_JDWP.DISCONNECT()
Process exited.
Disconnecting from the database QAV41PRODO.
Debugger disconnected from database.*
the stored procedure I am trying to run is as follows:
create or replace PROCEDURE EMP_SEL
(empID varchar2,
cur_out OUT SYS_REFCURSOR)
AS
BEGIN
OPEN cur_out FOR
SELECT * FROM EMP_TABLE
WHERE EMPID = 'empID'
ORDER BY EMPID;
END;
so, what would be the reason that I am not getting any result from this.
the select statement works fine and get me the results.
your help will be appreciated,
Thanks in advance!!!
what would be the reason that I am not getting any result from this. the select statement works fine and get me the results.
I think the problem is WHERE EMPID = 'empID' appears to be an attempt to restrict the result set to the passed parameter but you are in fact comparing the EMPID to the string 'empID'. That will probably return no matches.
Removing the quotes will create a namespace collision, effectively where 1=1, because SQL is not case sensitive and EMPID is the same as empID. So you need to give the parameter a different name to the column to avoid this e.g. p_empid.
create or replace PROCEDURE EMP_SEL
(p_empID varchar2,
cur_out OUT SYS_REFCURSOR)
AS
BEGIN
OPEN cur_out FOR
SELECT * FROM EMP_TABLE
WHERE EMPID = p_empID
ORDER BY EMPID;
END;
After removing quotes from 'empID', I try to compile and sql developer was hanged, that was another issue.
Then I found and killed the session for compiling the Stored Procedure,and compiled again applied the changes and it was successfully compiled.
Thanks for all your help...

stored procedure for select query not giving output

I am using sqlplus and have a table named users from which I wish to retrieve all values with the help of a stored procedure in oracle. Here is what I am trying to do -
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users
end;
/
When I hit return after this, I get the following error -
Warning: Procedure created with compilation errors.
Why does this happen? And how do I get the desired output? Help much appreciated!
To see the compilation errors use the show errors‌​ SQL*Plus command (which also works in SQL Developer), or query the user_errors view which works with any client. You can also query all_errors to see problems with objects that are not in your schema.
But you are just missing a semicolon after the select:
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users;
end;
/
You'll need a bind variable to be able to see the output in SQL*Plus, e.g.:
variable rc refcursor;
exec getall(:rc);
print rc
Notice the colon before the rc in the procedure call, which shows it's a bind variable reference. And exec is a shorthand anonymous block.
You might find it simpler to have a function that returns a ref cursor, or a pipelined function; or just query the table directly of course.

Error: java.sql.SqlException:Invalid column type

I have written following stored procedure to test procedure call from iReport designer.
Stored Procedure:
CREATE OR REPLACE PROCEDURE test(cursor1 out sys_refcursor) IS
BEGIN
OPEN cursor1 for
select person_id,first_name
from person
where rownum < 5;
END;
In my query window I am using following line to call this procedure.
{call test($P{cursor})}
where $P{cursor} is a parameter with class java.sql.ResultSet.
I have added ojdbc.jar file into my class path and connection is also successful.
When I run above statement for calling stored procedure it throws the error:
Error: java.sql.SqlException:Invalid column type
Can someone tell me what I did wrong here? Am i supposed to add any file or make any changes in the call to stored procedure?
The problem was in iReport field extractor. The solution for above problem is, we should analyse our stored procedure and create fields in iReport designer with the same name which are present in select clause of stored procedure.
After creating stored procedure, just drag and drop the fields on the report are and execute it. It will show the retrieved data.
This solution worked for me, so I am sharing it with you.

Including the schema name when calling a PL/SQL procedure doesn't work in one schema but does in another

This problem came up when trying out the Unit Testing capabilities of SQLDeveloper.
When running a test for a procedure that is created within my schema I am seeing an error however when the same procedure is run in one of the oracle supplied schemas it works without an issue.
SQL Developer generates the following calls:
1) This one doesn't work (error is shown below):
BEGIN
"IANC"."SIMPLE_PARAMETER"(P_X => 123);
END;
2) This one does:
BEGIN
"HR"."SIMPLE_PARAMETER"(P_X => 123);
END;
This is the procedure:
CREATE OR REPLACE PROCEDURE SIMPLE_PARAMETER
(
P_X IN NUMBER
)
IS
BEGIN
null;
END SIMPLE_PARAMETER;
The following is the output from SQLPLUS, where you can see when the procedure is run in my schema I see an error whilst when running the same procedure in another schema the procedure works as expected:
In case of need my I am using Oracle Enterprise Edition 11.2.0.1.0
Update
Screen shot showing procedure signatures
I should also mention that if I remove the schema name from the procedure call then the procedure runs and completes as expected.
Thanks in advance for any help received.
Are you sure that the SIMPLE_PARAMETER procedure in IANC is the same (or at least has the same signature) as the one in HR? What do you get from `DESCRIBE "IANC"."SIMPLE_PARAMETER".
(P.S. since your identifiers are all upper-case, you shouldn't need the double quotes at all.)
Added: Another possibility is that you have a package called IANC in the IANC schema, so Oracle is looking for a procedure in that package called SIMPLE_PARAMETER that does not exist. Example:
SQL> exec bigdecimaltest
PL/SQL procedure successfully completed.
SQL> exec dcosta.bigdecimaltest
PL/SQL procedure successfully completed.
SQL> create or replace package dcosta as
2 end;
3 /
Package created.
SQL> exec dcosta.bigdecimaltest
BEGIN dcosta.bigdecimaltest; END;
*
ERROR at line 1:
ORA-06550: line 1, column 14:
PLS-00302: component 'BIGDECIMALTEST' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
This seems like buggy behavior -- if the attempt to resolve the name as package.member doesn't succeed, I think Oracle ought to then try it as schema.object, but it looks like once it has found a match on the package name it won't reconsider that.

Resources