1.1, Oracle stored procedure Introduction:
A stored procedure is a collection of some pre-compiled SQL statements and stored in the database, call the stored procedure can be a lot of work to simplify the application developer
to reduce the transmission of data between the database and application server, for improving the efficiency of data processing is benefits.
advantage:
- It allows modular programming, that only need to create a process, later in the program can call any number of times the procedure.
- Allowed to execute faster, if a need to do a lot of repeat the SQL statement or stored procedure is faster than SQL statement is executed.
- Reduce network traffic, such as a SQL operation hundreds of lines of code needed to complete an execution statement, no need to send hundreds of lines of code in the network.
- Better security for the user does not have permission to execute a stored procedure, you may also authorize them to execute stored procedures.
1.2, create a stored procedure syntax:
1 the CREATE OR the REPLACE PROCEDURE stored procedure name (the param1 the IN the TYPE, the TYPE param2 OUT) 2 the AS . 3 Variable 1 type (value range); - a_dov VARCHAR (100) . 4 variable 2 type (value range); . 5 the BEGIN . 6 the SELECT COUNT ( * ) the INTO variable . 1 the fROM tABLE a the WHERE column name = the param1; - value takes a certain column or columns from the table, in order to use it must be assigned to the variable, then select. assignment is to camp into the defined syntax . 7 the IF . 8 (determination condition) THEN . 9 the SELECT column name INTO variable 2 the FROM TABLE A the WHERE column name = the param1; 10 dbms_output.put_line ( 'print information'); . 11 ELSIF (determination condition) THEN 12 is dbms_output.put_line ( 'print information'); 13 is the ELSE the Raise exception name (the NO_DATA_FOUND); 14 the END the IF ; 15 the EXCEPTION 16 the WHEN Others THEN . 17 the Rollback ; 18 is the END ;