oracle--Stored Procedures

Source: Internet
Author: User

A stored procedure is a program block stored in a data dictionary that can be shared among different users and applications, and enables optimization and reuse of programs.

First, the creation and execution of stored procedures

1. Create stored procedures using SQL commands

The syntax format is as follows:

SQL code create [or Replace] procedure [schema.] procedurename[(param1 mode1 dataType1,... N)] is |         As Var1 type1;         Var2 type2; ... begin statements; /* process body, to perform the operation * * END;

Where the mode1 represents the type of the parameter, like the parameter of the method, there are three types in, out, and in out; DataType1 represents the data type of the parameter.

Sample code:

SQL code Create or replace procedure Getmodulename (mid in number,mname out varchar) as begin select name into     Mname from T_module where Id=mid; End

2. Calling stored Procedures

The syntax format is as follows:

SQL code Exec[ute] procedurename[(param1,... N)]/* This is done at the command window.

Note:

You can also execute a defined stored procedure by entering the name of a stored procedure directly

Sample code:

SQL code DECLARE MID number: = 15;   Mname varchar (20);     Begin Getmodulename (mid,mname); Dbms_output.put_line (Mname | |   ' ********modulename '); End

Second, edit the stored procedure modification

While modifying a stored procedure and modifying a view, there is also an ALTER PROCEDURE statement, but it is used to recompile the stored procedure. If you want to modify a stored procedure that you have already defined, you still use the Create or replace procedure statement.

For example, modify the above getmodulename stored procedure as follows:

SQL code Create or replace procedure Getmodulename (mid number,mname out varchar) as BEGIN if mid > 0th       En select name into Mname from T_module where Id=mid;       else mname: = null;     End If; End

Third, delete stored procedures

When a stored procedure is no longer needed, it can be removed to free the memory resources it occupies.

The syntax format is as follows:

SQL code drop procedure [schema.] ProcedureName;

For example, delete the getmodulename stored procedure as follows:

SQL code drop procedure Getmodulename;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.