Plsql Knowledge grooming-stored procedures and Java calls

Source: Internet
Author: User

1 Description of stored procedures

A stored procedure is a PL/SQL block that is used for a specific operation, and is written by the flow control and the statement.
Stored procedures are compiled and SQL-optimized to be stored in the database server, and can only be called when used.

2 Advantages of stored procedures

1 Using stored procedures, you can implement the stored procedure design and coding work separately, as long as the stored procedure name, parameters, and return information to tell the coder.

2 Using stored procedures can reduce SQL injection attacks and provide system security.

3 The user executing the stored procedure must have permission to use the stored procedure. Users who do not have data manipulation privileges can only access data indirectly under system control.

4 the code of the stored procedure is placed directly in the database, which is usually called directly by the client through the name of the stored procedure, simplifying the operation logic of the client.

3 syntax for stored procedures

The stored procedure contains a three-part declaration, an execution part, and an exception. You can have a stored procedure with no parameters or with parameters.

Definition of Stored procedure:

Create [or Replace] procedure procedure_name

[(Parameter1[mode] datatype1,parameter2 [model] datatype2 ...)]

Is[as]

Begin

PL/SQL block;

End [Procedure_name]

Where: Procedure_name is the name of the stored procedure, parameter is used to specify parameters, model is used to specify the parameter pattern, datatype is used to specify the parameter type, is [as] for starting PL/SQL code block.

Note: 1, when you define parameters for a stored procedure, you can specify only the data type, and you cannot specify the data length.

2, when establishing a stored procedure, you can either specify the parameters of the stored procedure or provide no parameters.

3, the parameters of the stored procedures are mainly three types: input parameters (in), output parameters (out), input and output parameters (in out), where in is used to receive input parameters of the calling environment, out to pass the output data to the calling environment, in out not only to receive data, and to output data to the calling environment.

41 Simple Stored Procedures + debugging

Write a stored procedure--Modify the data in it

The query result for select COUNT (*) from table1 where name= ' Weiguo ' is count (*) =0

If two or more input parameters are involved, such as:

5 interface operations for stored procedures and Java programs

5.1 Stored procedures with no return value

Querying the database-displaying

5.2 Stored procedure with return value (non-list-single out parameter)

Note that the value in Proc.getstring (2) Here is not arbitrary, but corresponds to the Out column in the stored procedure, if out is in the first position, that is proc.getstring (1), if it is a third position, it is proc.getstring (3), of course, you can also have multiple return values, that is, add a few more out parameters.

Because the Oracle stored procedure does not return a value, all its return values are replaced by out parameters, and the list is no exception, but because it is a collection, it is not possible to use the general parameters, you must use Pagkage.

The stored procedure that returns a list is not used for me. To be implemented by building a package + cursor.


Plsql Knowledge grooming-stored procedures and Java calls

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.