Procedure
Procedures are used to perform specific actions. When building a procedure, you can specify both input parameters (in) and output parameters (out) . By using input parameters in the procedure, data can be passed to the execution part; by using output parameters, the data of the execution part can be passed to the application environment. In sqlplus, you can use the create procedure command to create a procedure.
The example is as follows:
1. Write a procedure, you can enter the employee name, and the new salary can modify the employee's salary
SQL> create procedure sun_pro3(sunName varchar2, newSal number) is
2 begin
3 -- the execution part, modify the salary according to the user name
4 update kkkk set sal=newSal where ename=sunName;
5 end;
6 /
Procedure created
to call the stored procedure
SQL> exec sun_pro3('SCOTT',4958);
PL/SQL procedure successfully completed
2. How to call the procedure?
Two methods: call and exec + procedure name, the difference is that if there are no parameters, exec + procedure name call + procedure name ()
3. How to call a stored procedure in a java program?
package comSun; import java.sql.Statement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; // Demonstrate how to use the jdbc_odbc bridge connection method public class TestOra { public static void main(String[] args) { try { //load driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // get the connection //The first "" is the configuration source, the second "" is the ORACLE user name, and the third "" is the password of the user name //The configuration source in the first "" requires the ODBC manager in the management tool in the control panel to create a data source to match Connection ct = DriverManager.getConnection("jdbc:odbc:testsp","scott","tiger"); //The same as mysql from below Statement sm = ct.createStatement(); ResultSet rs = sm.executeQuery("select * from emp"); while(rs.next()) { //Get the username from the database System.out.println("Username:"+rs.getString(2)); } } catch (Exception e) { e.printStackTrace (); } } }