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

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

Related

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.

stored procedure, msg 2812,

I've made a database and I'm trying to make some stored procedures for it,
I added a new query file to my database and i wrote the following code in it,
create procedure SEL_STUDENT
as
begin
select * from student
end
execute SEL_STUDENT
go
But anytime i try to execute the following line
execute SEL_STUDENT
it returns an error, saying,
Msg 2812, Level 16, State 62, Line 53
Could not find stored procedure 'SEL_STUDENT'
Please help me fix it.
Thanks.
I ran your code using a table from the AdventureWorks2012 database.
create procedure SEL_STUDENT
as
begin
select * from [Person].[Person]
end
go
execute SEL_STUDENT
And it works fine.
Although I have moved GO above execute SEL_STUDENT that is not the issue here as #CoOl points out because you specifically say you execute the stored procedure after your block of code.
The only possible explanation would be that you are querying execute SEL_STUDENT on the wrong database.
Try the following code -
USE [DatabaseName]
GO
execute SEL_STUDENT
Here, [DatabaseName] is the database where the stored procedure SEL_STUDENT table is stored.
Make sure your table is also stored in the same database or else you would have to modify select * from student to select * from [DatabaseName].[SchemaName].[student]
Additionally, you can use the Object Explorer to identify where your stored procedure has been saved. I am unable to post a snapshot of how to do this as my reputation is below 10.
EDIT : Now that my reputation is in two digits -
Kindly note that [dbo] is the default schema in SQL Server.
Because you are trying to execute the Stored Procedure which is not there yet.
Move GO above execute SEL_STUDENT
create procedure SEL_STUDENT
as
begin
select * from student
end
go
execute SEL_STUDENT

Stored Procedures for IBM DB2

I am new to stored procedures. Need to pick up some stored procedures for DB2(which I am also new to). The code I wrote is not working:
CREATE PROCEDURE sp_test
(
id NUMBER
)
BEGIN
IF NUMBER < 0 THEN
RAISE VALUE ERROR;
END IF;
SELECT * FROM student_tb
WHERE taskid = 'NUMBER';
END;
/
and this is the script (another file) which calls the stored procedure:
BEGIN
sp_test('15');
END;
I am not sure what is wrong. Hope someone can advise. Thank you.
I'm not an expert in DB2, but I'm pretty sure you have to CALL stored procs in DB2.
call sp_test('15');
or
execute (call sp_test('15'));
The syntax might be a little different for stored procedures that return a result set. Docs for DB2 on your target platform should explain the difference.

Can't execute stored procedure

I have created a stored procedure and can see it under the stored procedure node, but when trying to execute it doesn't find the procedure.
Under stored procedure node it is called dbo.CopyTable
exec CopyTable
CopyTable is undefined in red saying it does not exist. Why?
Even if I right-click on the procedure and say script stored procedure as execute to - the code it generates is underlined in red and cant find stored procedure either.
Ensure that the database selected contains the stored procedure CopyTable
USE YourDatabase
EXEC CopyTable
Try adding dbo and selecting the right database,
USE databaseName
GO
EXEC dbo.CopyTable
GO
Execute a Stored Procedure
Most likely you are just in the wrong database in the query window, you can specify the database like this:
EXEC [yourDBName].dbo.CopyTable
Reading on how to Execute a Stored Procedure
Considering your updated question:
Even if i rightclick on the procedure and say script stored procedure
as execute to - the code it generates is underlined in red and cant
find stored procedure either.
This could happen if your stored procedure is invalid. Please double-check the validity of the SPROC and ensure the tables it references exist, etc.
Try running your CREATE PROCEDURE. Highlight it, f5 it, and then make sure it runs before you call it elsewhere.
Maybe in your procedure you've accidentally cut-pasted your script name (dbo.CopyTable), say something like...
SELECT * FROM dbo.CopyTable
WHERE ClientId = #ClientId
RETURN
Then when you call your proc you get 'invalid object name dbo.CopyTable' and assume sql is having trouble finding the stored-proc ... which isn't the problem, its finding and running the proc but its actually a problem within the proc.

Calling a Stored Procedure in Oracle

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.