Procedure is not working on Oracle database - oracle

I am trying to write a simple "Hello World" procedure .... but it is not working
Code :
CREATE OR REPLACE PROCEDURE greetings
AS
BEGIN
dbms_output.put_line('Hello World!');
END;
/
After that I executed it like this :
EXECUTE greetings;
but I get an error :
ORA-00900: invalid SQL statement
Images are here :
Please help out as soon as possible ...thanks :)

I believe EXECUTE is a SQL*Plus statement. It's not a valid SQL statement.
The error message being returned ORA-00900: invalid SQL statement makes it appear that the client you are using is not emulating the SQL*Plus EXEC statement.
The general form for executing a PL/SQL procedure is to execute an anonymous PL/SQL block.
BEGIN greetings(); END;
/

Related

Error in printing bind variables in PL/SQL

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>

Dynamic Procedure Execution

Hi I have to execute a remote call ...
DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO#DB_LINK()
... from a stored procedure.
As the value of DB_LINK is to be obtained during runtime. It should be executed dynamically. I tried to use
EXECUTE IMMEDIATE ' DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO#'||DB_LINK||'()';
But I get the following error
ORA-00900: invalid SQL statement
Can anyone advise me on how to execute the Stored Procedure dynamically?
The clue lies in the precise wording of the error message: invalid SQL statement. As the PL/SQL manual says, EXECUTE IMMEDIATE is for executing dynamic SQL statements.
You are executing a procedure call i.e. PL/SQL not SQL. So you need to pass an anonymous block to EXECUTE IMMEDIATE:
EXECUTE IMMEDIATE
'begin DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO#'||DB_LINK||'() ; end;'
;
DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO takes no parameters, so the empty brackets are optional. By all means include them if they make you feel happier.
EXECUTE IMMEDIATE 'DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO#'||DB_LINK();
should work if DB_LINK is a global function returning a VARCHAR2 string.

How to excecute stored procedure with parameter in Oracle

My procedure is like this:
CREATE OR replace PROCEDURE rs_pes (c1 IN OUT SYS_REFCURSOR,
pi_prod_type_code IN VARCHAR2,
pi_entry_date IN VARCHAR2,
pi_dealer IN VARCHAR2,
pi_adv IN VARCHAR2 )
And, I'm trying to execure it like this:
execute RS_PES('Investments Series 2',
'31-12-2012',
'All Dealer',
'All Adv')
I'm getting incorrect syntax error.
ORA-00900: Invalid SQL statement
00900.00000 - Invalid SQL statement
What I'm doing wrong, how to execute this? I'm new to Oracle.
Execute is a SQL*Plus command which basically wraps your procedure call around BEGIN/END statements. This won't work anywhere else except SQL*Plus
If you want to execute the procedure in Oracle SQL Developer, wrap it in BEGIN/END block
BEGIN
RS_PES('Investments Series 2',
'31-12-2012',
'All Dealer',
'All Adv');
END;
Also, your procedure has 5 parameters, while you're setting only 4. You need to fix that.

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.

Can't call stored procedure from PL/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;

Resources