PL/SQL算术运算符操作实例

所有PL/SQL支持的算术运算符:+、-、*、/、**(乘方)。给出的操作实例源码:

-- Created on 2018/3/22 by E.WANG 
declare 
  -- 声明两个整型变量
  first_int integer;
  second_int integer;
  --声明一个双精度变量存放运算结果
  result_dub double precision;
begin
  /*
  算数运算符:+、-、*、/、**(乘方)
  */
  --加法
  first_int:=10;
  second_int:=30;
  result_dub:=first_int+second_int;
  dbms_output.put_line('The result of add:' || result_dub);
  
  --减法
  first_int:=789654123;
  second_int:=4561230;
  result_dub:=first_int-second_int;
  dbms_output.put_line('The result of sub:' || result_dub);
  
  --乘法
  first_int:=456;
  second_int:=789;
  result_dub:=first_int*second_int;
  dbms_output.put_line('The result of mul:' || result_dub);
  
  --除法
  first_int:=78965;
  second_int:=234;
  result_dub:=first_int/second_int;
  dbms_output.put_line('The result of div:' || result_dub);
  
  --乘方
  first_int:=2;
  second_int:=10;
  result_dub:=first_int**second_int;
  dbms_output.put_line('The result of power:' || result_dub);
  
  --组合运算
  first_int:=2;
  second_int:=10;
  result_dub:=first_int**second_int+first_int-second_int*first_int+second_int/first_int;
  dbms_output.put_line('The result of combine:' || result_dub);
  
end;

给出窗口截图:

PL/SQL算术运算符操作实例_第1张图片

运行结果截图:

PL/SQL算术运算符操作实例_第2张图片

你可能感兴趣的:(数据库知识库)