Home » SQL & PL/SQL » SQL & PL/SQL » What is Stored Procedure (PL/SQL Toad Oracle 10g)
What is Stored Procedure [message #599145] Tue, 22 October 2013 09:43 Go to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

"Stored Procedure" , Read many topics about it , searched it on google , saw many videos
what i got simple procedure programs and everyone is calling and explaining them as "Stored Procedure"
. My question is if it is similar to Normal Procedure then why "Stored Procedure" term is being used
what does "Stored" means , What is the difference between Procedure and Stored Procedure.
What is the syntax and when should we use Stored Procedure and Give some examples also to show the difference between
Normal Procedures and Stored Procedure. Thanks.
Re: What is Stored Procedure [message #599146 is a reply to message #599145] Tue, 22 October 2013 09:48 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://docs.oracle.com/cd/E16655_01/server.121/e17633/glossary.htm#CNCPT44531

how do you invoke a PL/SQL procedure that does not have a name?
Re: What is Stored Procedure [message #599148 is a reply to message #599145] Tue, 22 October 2013 09:57 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
The distinction is not "stored" or "normal", but "stored" or "anonymous".
Re: What is Stored Procedure [message #599149 is a reply to message #599145] Tue, 22 October 2013 09:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

There is no difference (until 12c), stored is there in the opposite of anonymous PL/SQL block which is not stored.

In 12c you can define function in a SQL statement, this is then a not stored PL/SQL function.

Re: What is Stored Procedure [message #599156 is a reply to message #599149] Tue, 22 October 2013 11:06 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Michel Cadot wrote on Tue, 22 October 2013 10:58

There is no difference (until 12c), stored is there in the opposite of anonymous PL/SQL block which is not stored.


You don't need 12 to have a stored procedure that is not stored in database. Just declare it in an anonymous block. But in all the cases stored procedure is stored - what changes is scope. If stored procedure is declared at database level you can reference it anywhere you want and Oracle will find it (since it is stored in database it is always available). If stored procedure is declared in an anonymous block you can reference it anywhere within that block (and all its inner blocks). If it is created in WITH clause, you can reference it anywhere within that SQL statement.

SY.
Re: What is Stored Procedure [message #599159 is a reply to message #599149] Tue, 22 October 2013 12:11 Go to previous messageGo to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

I did not get whatever you said can you provide few examples with queries to
clear the difference between anonymous or stored procedure. Thanks
Re: What is Stored Procedure [message #599161 is a reply to message #599159] Tue, 22 October 2013 12:20 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Overview of PL/SQL Program Units
icon2.gif  Re: What is Stored Procedure [message #599162 is a reply to message #599159] Tue, 22 October 2013 12:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Stored procedure:
QL> create or replace procedure p is begin null; end;
  2  /

Procedure created.

SQL> exec p;

PL/SQL procedure successfully completed.

Not stored procedure (as er Solomon's remark):
SQL> declare
  2    procedure p2 is begin null; end;
  3  begin
  4    p2;
  5    p;
  6  end;
  7  /

PL/SQL procedure successfully completed.

But now:
SQL> exec p2;
BEGIN p2; END;

      *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'P2' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

[Updated on: Tue, 22 October 2013 12:20]

Report message to a moderator

Re: What is Stored Procedure [message #599178 is a reply to message #599162] Tue, 22 October 2013 14:08 Go to previous messageGo to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

till yet i have created procedure using "create or replace" only
if i am getting you then the procedure that we create using "create" clause are stored procedure
and we can access or call them using execute/exec clause.

anonymous procedure are those that we create using declare clause and we can access them inside that block only and
we cant access or call them using execute.

SQL> declare
  2    procedure p2 is begin null; end;
  3  begin
  4    p2;
  5    p;
  6  end;
  7  /

and can you explain syntax and what is actually happening in above query.
and tell me how much did i understand.
Thanks


Re: What is Stored Procedure [message #599179 is a reply to message #599178] Tue, 22 October 2013 14:34 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
  • DECLARE
    - marks the beginning of the declaration section
  • procedure p2 is begin null; end;
    - this is a "private" procedure (private that this anonymous PL/SQL block). It does nothing (NULL), but the basic syntax is satisfied - it has its name, begin and end, and at least one command in between. It is not accessible outside of this PL/SQL block (the final example Michel provided)
  • BEGIN
    - let's go!
  • p2;
    - call the private procedure whose name is p2
  • p;
    - call a stored procedure (Michel created it at the beginning of his example)
  • END;
    - The End
Nothing is actually happening here; everything works, but nothing has been done.
Re: What is Stored Procedure [message #599206 is a reply to message #599179] Wed, 23 October 2013 00:31 Go to previous messageGo to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

thanks for explaining , i was confused because he used "end;" in declare section , now got it
but may i get proper syntax please.
Re: What is Stored Procedure [message #599208 is a reply to message #599161] Wed, 23 October 2013 00:40 Go to previous messageGo to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

thanks lalit for this useful link , finally came to know what are anonymous blocks and stored program units. Smile
Re: What is Stored Procedure [message #599223 is a reply to message #599206] Wed, 23 October 2013 01:35 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
jgjeetu wrote on Wed, 23 October 2013 07:31

but may i get proper syntax please.

What "proper" syntax? Michel already posted it ...

If you are interested in details, read documentation. You already got the link.
Re: What is Stored Procedure [message #599232 is a reply to message #599223] Wed, 23 October 2013 02:41 Go to previous messageGo to next message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

no michel have posted queries only , n i have read documentation also but there is no example or syntax for creating procedure using declare clause.
i am just asking for the syntax because still i am not able to understand why did he put "end;" before begin .
if i get the syntax then i will be able to understand it properly. Thanks
Re: What is Stored Procedure [message #599239 is a reply to message #599232] Wed, 23 October 2013 03:19 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
jgjeetu wrote on Wed, 23 October 2013 08:41
i am not able to understand why did he put "end;" before begin .
This has already been explained by LF
Quote:
procedure p2 is begin null; end;
- this is a "private" procedure (private that this anonymous PL/SQL block). It does nothing (NULL), but the basic syntax is satisfied - it has its name, begin and end, and at least one command in between.


Quote:
if i get the syntax then i will be able to understand it properly. Thanks

declare
   --local procedure declaration
    procedure procname (parameters) is
      --variable declarations
    begin
       statements;
    end;
begin
   statements;
end;
Re: What is Stored Procedure [message #599249 is a reply to message #599239] Wed, 23 October 2013 05:07 Go to previous message
jgjeetu
Messages: 373
Registered: July 2013
Location: www.Orafaq.com/Forum
Senior Member

thanks , read lf's answer again , now finally it's clear.
Previous Topic: Mysterious behaviour of Oracle SQL
Next Topic: How to extract first 3 characters from each word in a string/sentence and separate with underscore?
Goto Forum:
  


Current Time: Fri Apr 19 08:19:45 CDT 2024