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.
Related
Actually I am creating stored procedure with substitution, while trying to compile the procedure, I get the popup to enter the substitution values in compiling itself, Instead of getting popup while execution.
Please share me your idea to compile the procedure without asking the substitution
In SQL*Plus or Oracle SQL Developer, you'd SET DEFINE OFF. You tagged the question with PL/SQL Developer tag (which is a tool I don't use), but - see if this helps.
However: I'd suggest you not to do it that way. If you're creating a stored procedure, then use its parameters, don't ask for substitution variables. Something like this:
SQL> set serveroutput on
SQL> create or replace procedure p_test (par_deptno in dept.deptno%type) is
2 begin
3 dbms_output.put_line('Department ' || par_deptno);
4 end;
5 /
Procedure created.
SQL> exec p_test(10);
Department 10
PL/SQL procedure successfully completed.
You can now reuse such a procedure, passing any parameter value you want.
The way you're doing it now:
SQL> create or replace procedure p_test is
2 begin
3 dbms_output.put_line('Department ' || &par_deptno);
4 end;
5 /
Enter value for par_deptno: 25
old 3: dbms_output.put_line('Department ' || &par_deptno);
new 3: dbms_output.put_line('Department ' || 25);
Procedure created.
SQL> exec p_test
Department 25
PL/SQL procedure successfully completed.
SQL>
you can run the procedure many times, but it'll always display (i.e. use) the same value, throughout that session. Once you exit and log in again, procedure will always use the same value.
You cannot! A substitution variable acts like a find-replace operation in the client application at the time the statement is run; the database does NOT see the substitution variable as the client application you are using will have already performed the find-replace operation. Which, for a procedure, would be at the time the CREATE PROCEDURE statement is sent from the client to the database to be compiled. It is NOT an operation that the database performs.
If you try it in a client that does not support substitution variables (or in a client that does support it after turning off substitution variables using, for example, the command SET DEFINE OFF in the client application) then you will get a compilation error. db<>fiddle
If you want to use substitution variables then use them in the anonymous block when you call the procedure.
An example procedure would take parameters and have no substitution variable:
CREATE PROCEDURE procedure_name(
p_value IN NUMBER
)
IS
BEGIN
-- Do something
DBMS_OUTPUT.PUT_LINE( p_value );
END;
/
Then when you want to execute the procedure you can use a substitution variable in the calling block:
BEGIN
procedure_name( &value );
END;
/
I am trying to print bind variable in PL/SQL. Upon executing the code, a new window pops up asking me to enter a value for the same. Submitting my response takes me to the previous page and I get an error ORA-00900: invalid SQL statement.
I am using Oracle Database 10g Express Edition.
Help is appreciated. Thanks in advance
Here's the code for your reference:
VARIABLE v_bind VARCHAR2(10);
BEGIN
:v_bind:='Hello';
DBMS_OUTPUT.PUT_LINE(:v_bind);
END;
"Submitting response"? "Previous page"? Which tool do you use?
In SQL*Plus, it works as expected:
SQL> set serveroutput on
SQL> var v_bind varchar2(10);
SQL> begin
2 :v_bind := 'Hello';
3 dbms_output.put_line(:v_bind);
4 end;
5 /
Hello
PL/SQL procedure successfully completed.
SQL>
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.
create or replace procedure minvalue(x in number,y in number,z in number)
as
begin
if x< y then
z := x;
else
z:= y;
end if;
end;
/
compilation error.
in this code, x and y are parameters which takes values when user run this procedure and z take out the answer . this code find minimum values between x and y ,and store minimum value through z.
I created this procedure on sql>. now how I can put this in buffer again. so that i can modify /enhance it. But I don't know how to open this procedure through sql command. Pls help me.
In SQL*Plus the ed command will open your last statement in the default editor (unless you've defined something else in your login.sql script).
It's good practice to write code as scripts in a decent text editor or IDE and run those scripts at the SQL*Plus command line.
So, the actual error is this:
create or replace minvalue
That should be create or replace procedure minvalue. Once you clear the ORA-00922 missing or invalid option exception the next issue is:
c := x;
You haven't declared a variable c so this will hurl an ORA-00904 invalid identifier exception.
You just have to execute your statement again, it does as it says create or replace the stored procedure.
If you want to know which errors occured, enter show errors after executing.
PS: You dont't use Parameter zso why is it there? You'll need a function with a return value not a procedure if you want to return something.
Compile the PL/SQL code.
Use SHOW ERROR to validate.
If you see any compilation errors, use ed to modify the code.
Save the afiedt.buf file.
You will see the modified code loaded, just use / to recompile the code.
For example,
SQL> set serveroutput on;
SQL>
SQL> BEGIN
2 NULL;
3 END;
4 /
PL/SQL procedure successfully completed.
SQL> SHOW ERROR
No errors.
SQL> ed
Wrote file afiedt.buf
1 BEGIN
2 DBMS_OUTPUT.pUT_LINE('code modified');
3* END;
SQL> /
code modified
PL/SQL procedure successfully completed.
SQL>
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;