PL/SQL (procedural language/sql) is a procedural language.
PL/SQL is based on (block) blocks, and the entire PL/SQL block is divided into three parts
1. Declaration (Declare)
2. Execution (beginning with Begin)
3. Exception handling (starting with exception)
The syntax format for PL/SQL is as follows:
[Declare] -- Declaration section Optional BEGIN-- Executive Section required [EXCEPTION] -- exception handling Section optional END
PL/SQL Simple example:
--==========================================--Author:oliver QIN--date:2015-12-13--desc: Write a PL/SQL block to calculate the sum of two numbers and the quotient of the difference--==========================================Sql> SetServeroutput onSQL> Declare 2Aint:= -; 3Bint:= $; 4C Number; 5 begin 6C:=(A+b/(A-b); 7Dbms_output.put_line (c); 8Exception9 whenZero_divide Then TenDbms_output.put_line ('the divisor cannot be zero! '); One End; A /-3PL/The SQL process has completed successfully. --Change the value of B to 100 by using edit and create a case with a divisor of 0 SQL>Edit is writtenfileAfiedt.buf1 Declare 2Aint:= -; 3Bint:= -; 4C Number; 5 begin 6C:=(A+b/(A-b); 7Dbms_output.put_line (c); 8Exception9 whenZero_divide Then TenDbms_output.put_line ('the divisor cannot be zero! '); One* End; SQL> /the divisor cannot be zero! PL/The SQL process has completed successfully.
In the entire code snippet, set Serveroutput on is used because the command is first needed in sql*plus to open the function that displays execution results on the server side.
Oracle calculates the difference between two integers and the two integers with quotient