21. Oracle PL/SQL classification one stored procedure

Source: Internet
Author: User

Stored procedures are used to perform specific operations when a stored procedure is established, you can specify either an input parameter (in) or an output parameter (out), you can pass the data to the execution part by using the input parameters in the procedure, and you can pass the execution part of the data to the application environment by using the output parameters. You can use the CREATE PROCEDURE command in Sqlplus to establish the process.
Examples are as follows:
1. Consider writing a stored procedure that allows you to enter an employee's name, a new salary, to modify the employee's salary

--Revise salary according to employee's name
CREATE PROCEDURE sp_update (uname VARCHAR2, newsal number) is
BEGIN
Update emp set sal=newsal where Ename=uname;
END;
/


2. There are two ways to invoke a stored procedure: exec, call

--Call the stored procedure using exec
sql> exec sp_update (' Zhangsan ', 888);
Sql> commit;


3. How to invoke a stored procedure in a Java program

Package junit.test;

Import java.sql.CallableStatement;
Import java.sql.Connection;
Import Java.sql.DriverManager;

/**
* Demo Java program calls Oracle's stored procedure case
*
* @author Jiqinlin
*
*/
public class Proceduretest {

public static void Main (string[] args) {

try {
1. Load Driver
Class.forName ("Oracle.jdbc.driver.OracleDriver");
2. Get Connected
Connection ct = drivermanager.getconnection (
"Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "Scott", "Oracle");

3. Create CallableStatement
CallableStatement cs = Ct.preparecall ("{Call Sp_update (?,?)}");
4. Assigning Values to
Cs.setstring (1, "SMITH");
Cs.setint (2, 4444);
5. Implementation
Cs.execute ();
Shut down
Cs.close ();
Ct.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}
}

21. Oracle PL/SQL classification one stored procedure

Related Article

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.