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
Is
BEGIN
Set Salwhere ename=uname;
END;
/
2. There are two ways to invoke a stored procedure: exec, call
-- call the stored procedure using exec
SQLexec sp_update ('zhangsan888);
SQLcommit;
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
*
*@authorJiqinlin
*
*/
PublicClass Proceduretest {
PublicStaticvoid 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. Assign a value
Cs.setstring (1, "SMITH");
Cs.setint (2, 4444);
// 5. Execute
Cs.execute ();
// close
Cs.close ();
Ct.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}
}
Question: How do I use procedure return values?
Special note: For the stored procedures we will give you a detailed introduction in the future, now please everyone first has a concept.