Can't call stored procedure from PL/SQL - oracle

I have this simple stored procedure that I wrote and executed in PL/SQL.
CREATE OR REPLACE PROCEDURE test_sp
IS
BEGIN
dbms_output.put_line('Test');
END;
I am trying to call it within PL/SQL like this:
CALL test_sp;
But I end up getting this error:
ORA-06576: not a valid function or procedure name
This is a simple call, is there a syntax error or am I missing some kind of permission?

If you are using call then you will want to include parentheses. The oracle docs show call using these:
call test_sp();
Or you can use exec:
exec test_sp;
Or you can just wrap your stored procedure name in an anonymous block:
begin
test_sp;
end;

Related

pass an array from Pro*c to Procedure

We have a user-defined datatype in Oracle which is used in a procedure as an input argument. We are trying to call this procedure from Pro*C.
In Oracle, the user-defined data type is VARRAY(21) of VARCHAR2(500).
In Pro*C we tried similar to the sample program 9 in https://docs.oracle.com/cd/B12037_01/appdev.101/a97269/pc_07pls.htm#i2344
On compiling we are getting the error "Wrong number or types of arguments in call". Pro*C code
Any help on how to pass an array to a procedure is appreciated.
Pay attention that this declaration is happening into an EXEC SQL EXECUTE block, while you're doing it into a DECLARE SECTION.
Do the declaration and assignment like this:
EXEC SQL EXECUTE
DECLARE
/* your declaration here*/
BEGIN
/* call to the procedure here*/
END;
END-EXEC;

Calling another PL/SQL procedure within a procedure

I'm new to PL/SQL & would greatly appreciate help in this. I've created a procedure to copy contracts. Now I want to call another procedure from within this procedure which shall copy all the programs related to the contract I'm copying. One contract can have multiple programs.
You cal call another procedure in another package by using PackageName.ProcedureName(vcParameters => 'InputParameter1'); If the procedure is in the same package you could do it without the PackageName, so just ProcedureName(vcParameters => 'InputParameter1');
You call a procedure by simply putting its name and parameters in your code, e.g.
begin
dbms_output.put_line('Demo');
end;
or within a procedure,
create or replace procedure demo
as
begin
dbms_output.put_line('Demo');
end;
I have used dbms_output.put_line as an example of a procedure, but obviously any other procedure would be called the same way:
begin
foo;
bar(1);
demo(true, 'Bananas', date '2018-01-01');
end;
For some reason, many beginners are tempted to add exec before the procedure call. I don't know where that comes from because PL/SQL has no such keyword. Possibly they are thinking of the SQL*Plus execute command, which can be abbreviated to exec. However, SQL*Plus is a separate command line utility with its own commands that have nothing to do with the PL/SQL language.

How to execute procedure in APEX SQL script?

I am trying to understand how to use multiple procedures in APEX SQL script. First I don't really need stored procedure, but not sure how to declare simple procedure in APEX SQL script. So this is my attempt:
create or replace procedure test1 as
begin
DBMS_OUTPUT.ENABLE;
dbms_output.put_line('test1');
end;
execute test1;
This gives me an error:
Error at line 7: PLS-00103: Encountered the symbol "EXECUTE"
So questions - how to create regular/not stored/ procedures in one SQL script and then call them. What is the entry point of execution in APEX SQL script?
UPD (At the first time I understood question totally wrong)
Correct version of a script:
create or replace procedure test1 as
begin
DBMS_OUTPUT.ENABLE;
dbms_output.put_line('test1');
end;
/
begin
test1;
end;
/
Documentation says, that script can contain inly SQL and PL/SQL commands. Commands of sqlplus will be ignored.
OLD VERSION (Let stay here)
In APEX pages you can use PL/SQL anonymous blocks. For example, you can create process (APEX has some types of them) or PL/SQL region, and use following:
declare
...
begin
some_proc(:P_MY_ITEM);
end;
Here you can invoke any procedure and do anything else that allowed by PL/SQL. Also you can use parameters like :P_ITEM_NAME to get and set values of page and application items.

EXECUTE recognizes a stored procedure, CALL does not

When I try to run a stored procedure using EXECUTE, the proc runs fine. When I use CALL, I get "ORA-06576: not a valid function or procedure name". I am connecting directly via toad. Why can't I use call?
I have tried both of these Calls:
CALL(BPMS_OWNER.DAILY_PARTITION_NOROTATE('MIP_TEST',5,5,'MIP_TEST_',5,FALSE,TRUE));
CALL BPMS_OWNER.DAILY_PARTITION_NOROTATE('MIP_TEST',5,5,'MIP_TEST_',5,FALSE,TRUE);
The reason I need to use CALL is that our platform parses SQL before we send it to Oracle, which for whatever reason does not support EXECUTE.
Simply because call requires that you add parenthesis, for instance, call my_proc()
If I set up a little test:
SQL>
SQL> create or replace procedure test is
2 begin
3 dbms_output.put_line('hi');
4 end;
5 /
Procedure created.
And run this several different ways you'll see
SQL> exec test
hi
PL/SQL procedure successfully completed.
SQL> call test;
call test
*
ERROR at line 1:
ORA-06576: not a valid function or procedure name
SQL> call test();
hi
Call completed.
Why do you need to use call? Isn't exec, execute and begin ... end enough?
Based on your update the problem is the booleans, which call doesn't seem to support. Creating yet another small procedure
SQL> create or replace procedure test (Pbool boolean ) is
2 begin
3 if Pbool then
4 dbms_output.put_line('true');
5 else
6 dbms_output.put_line('false');
7 end if;
8 end;
9 /
Procedure created.
SQL> show error
No errors.
and running it proves this
SQL> call test(true);
call test(true)
*
ERROR at line 1:
ORA-06576: not a valid function or procedure name
I don't quite understand your reasoning behind why you can't use exec or execute but assuming these are both off limits why not just use a traditional, anonymous PL/SQL block?
SQL> begin
2 test(true);
3 end;
4 /
true
PL/SQL procedure successfully completed.

Execute Oracle Stored Proc

I have an oracle stored proc with signiture: (part of package: Contractor)
PROCEDURE usp_sel_contractors(g_contractors OUT sel_contractor);
I am trying to execute it like:
execute Contractor.usp_sel_contractors;
I'm used to MSSqlServer. This seems like it should be strait forward.
I keep getting error:
Invalid Sql Statement
Thanks!
Assuming sel_contractor is a ref cursor type, you could do this in SQL Plus:
var rc refcursor
exec usp_sel_contractors(:rc)
print rc
I'm not sure why you'd be getting that specific error message, but the obvious problem is that the procedure has a parameter and you're not passing one. Since it's an OUT parameter you would need to pass a variable of the appropriate type which will be populated by the procedure.
For example:
DECLARE
my_contractors sel_contractor;
BEGIN
usp_sel_contractors( my_contractors );
// Do something with the contents of my_contractors here
END;
/

Resources