Calling a Stored Procedure in Oracle - sql

This should be something fairly simple and straight-forward but for some reason I can't get it to work. I've created my SProc like so:
create or replace procedure zadmit_migrate_data (zadmit_seq_no number)
is
thisPIDM number;
begin
select pidm into thisPIDM
from saturn.zadmit_core_data
where pk_seqno = zadmit_seq_no;
if thisPIDM is not null then
dbms_output.put_line('thisPIDM is NOT null!');
else
dbms_output.put_line('thisPIDM is null!');
end if;
end zadmit_migrate_data;
And now I've trying to call it like this:
call zadmit_migrate_data(4);
And then I get this error:
ORA-06575 Package or function is in an invalid state.
So I tried this:
execute zadmit_core_data(4);
And instead get this error:
ORA-00900 Invalid SQL statement.
It might be less time consuming to point out where I'm going right, but if anyone can tell me where I'm going wrong that would probably be more useful. :)

If you Google for error ORA-06575, you find:
You tried to execute an SQL statement
that referenced a PLSQL function that
is in an invalid state. This happens
when the function is compiled with
errors.
You can resolve this by:
Correct the errors and then re-compile
the function. Then re-execute the SQL
statement.
Once your procedure compiles, you could execute it like:
begin
zadmit_migrate_data(4);
end;

Shouldn't your execute statement be "execute zadmit_migrate_data(4);" ?
At any rate, running this command:
SELECT object_name FROM user_objects WHERE status='INVALID';
will tell you if you procedure is valid or not.
Executing your CREATE or REPLACE ... command, then immediately executing the command
SHOW ERRORS
should tell you what compilation errors were encountered.

Run this
SQL> alter procedure zadmit_migrate_data compile;
SQL> show errors
Given the simplicity of your procedure, it shouldn't be hard to diagnose the resulting error stack.

Related

What have i gotten wrong for this stored procedure not to execute?

Here is the stored procedure and how I created it
CREATE OR REPLACE STORED PROCEDURE SimpleSelect()
AS
BEGIN
SELECT * FROM Permissions
END;
/
CALL SimpleSelect();
When creating the procedure I get the error
"Success with some compilation errors"
and when running the CALL command I get that the SQL command not properly ended.
It is important to know which database do you use. Some of this advice's will come in handy in many databases but some will not...
Do you have a table called Permissions already created ? If not, create it.
Please put a ; after the SELECT statement. Like this:
SELECT * FROM Permissions;
In MySQL this will not return error:
CREATE PROCEDURE SimpleSelect()
BEGIN
SELECT * FROM Permissions;
END;
/
When you fix your procedure the call command will work just fine...
Cheers!
Here is the DEMO

oracle sql developer first time user

I am new to plsql and trying to use oracle sql developer, I try to run a simple procedure with dbms output line and i get the following error,
ora-00904
, the code is
create or replace PROCEDURE proc_101 IS
v_string_tx VARCHAR2(256) := 'Hello World';
BEGIN
dbms_output.put_line(v_string_tx);
END;
whether i click the run(green colour) or debug(red colour) i get the same error.
You can see from the above code, procedure doesn't access any objects but still i get the same error.
Your procedure is fine. You may not have permissions to be able to Create a Procedure. If this is the case test your procedure/code without actually Creating it in the Database first. For example, when I'm testing code in my Production database my oracle user cannot Create Procedures, Packages, Tables etc... And so I test my Procedures within my Own PL/SQL Blocks. When the code is good to go I can get a database administrator to Create the Procedures and/or Packages for me.
The below screenshot is code that simply tests the Procedure:
The below screenshot is code that does much more and tests the Procedure from within a PL/SQL Block
For more advanced situations this allows you to do so much more as you can create all sorts of Procedures/Functions and/or Cursors and test them immediately without needing to CREATE these objects in your Oracle Database.
I'd say that there's some other code in the worksheet which raises that error, not just the CREATE PROCEDURE you posted. For example, something like this SQL*Plus example (just to show what's going on - you'd get the same result in SQL Developer):
SQL> select pixie from dual;
select pixie from dual
*
ERROR at line 1:
ORA-00904: "PIXIE": invalid identifier
SQL>
SQL> create or replace PROCEDURE proc_101 IS
2 v_string_tx VARCHAR2(256) := 'Hello World';
3 BEGIN
4 dbms_output.put_line(v_string_tx);
5 END;
6 /
Procedure created.
SQL>
See? The first part raised ORA-00904 as there's no PIXIE column in DUAL, while the procedure is created correctly.
So - remove code which fails and everything should be OK.
Check with your DBA to make sure the dbms_output package has been installed on your database, and that you have permissions on it.

How to "select" inside a stored procedure or a UDF in DB2 LUW?

I believe this question is very trivial. I' unable to select rows inside a stored procedure that I defined, nor inside a UDF. Here is the syntax that I used:
Create Or Replace Procedure GenerateSequence(
In InternalUnitID SmallInt,
In ObjectTypeID SmallInt)
Language SQL
Dynamic Result Sets 1
Not Deterministic
No External Action
Modifies SQL Data
Commit On Return Yes
Begin
Select Number
From Sequence
Where InternalUnit=InternalUnitID
And ObjectType=ObjectTypeID;
End
If I try to create the above procedure (by putting the definition in a SQL file and running it). I get the following error message:
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "Select Number From Sequence Where Intern" was
found following "n Return Yes Begin ". Expected tokens may include: "".
LINE NUMBER=21. SQLSTATE=42601
Any clue what can be the cause of this problem?
My environment is DB2 10.5 Express on Windows.
My problem was that I needed to use a cursor in order to return the result set to the caller of the stored procedure.
References:
CREATE PROCEDURE (SQL) statement
Compound SQL (compiled) statement

PL/SQL: Having trouble creating procedure

I'm having issues creating a simple procedure in oracle 10g
All I'm trying to do is this procedure:
create procedure greetings
is
begin
dbms_output.put_line('Hello');
end;
I type this into the prompt:
#proc1.sql
and I get only this:
6
and I'm unable to get back to the prompt again without ctrl+c. I know it's ghetto but I'm using SSH if that helps solve the problem.
You need a / on a line by itself after the final end; so sqlplus will know it's time to execute. (sqlplus somehow fails to know how to parse the language which is its sole purpose for existing, so it doesn't know that the last end; you entered is the one that terminates the create command.)

ORA:00900 Invalid sql statement

i created a procedure with 32 in argument,it sucessfully created.but when i am executing this in back end oracle the errror came ORA:00900 Invalid sql statement
Use:
SQL> alter procedure [your procedure name here] compile;
SQL> show errors
...to be able to diagnose the issue from the resulting error output.
Also look at view USER_ERRORS.
Sometimes, show errors does not show anything when in fact there are errors. Especially after alter compile.
Finally, re-compile in TOAD or SQL Developer and you can easily navigate to the error.
In Oracle SQL Developer you should execute it this way:
BEGIN
YOUR_PROCEDURE(PARAM1, PARAM2);
END;
If you use EXECUTE or EXEC (which work in SqlPlus) you get the ORA-00900 error.