zoukankan      html  css  js  c++  java
  • PL/SQL与TSQL比较(一) 用户自定义函数

    场景一:

      创建一个返回"Hello World!"字符串的函数。

    PL/SQL:

    create or replace function get_hello_msg
    return varchar2 as
    begin
     return 'Hello World!';
    end get_hello_msg;

    /

    执行:

    select get_hello_msg msg from dual;

    T-SQL:

    create function dbo.fnGetHelloMsg()
    returns varchar(50)
    as
    begin
     return 'Hello World!'
    end
    go

    执行:

    select dbo.fnGetHelloMsg() msg

    看以看出:

    T-SQL中的函数必须要有括号,不然会报错。

    场景二:

      计算工资所得税(带有参数)

    PL/SQL:

    create or replace function get_tax(p_salary number)
    return number as
    begin
     declare tax_salary number;
     begin
      tax_salary := p_salary - 2000;
      
      if tax_salary<=0 then
       return 0;
      end if;
      
      if tax_salary<=500 then
       return tax_salary*5/100;
      end if;
      
      if tax_salary<=2000 then
       return tax_salary*10/100 - 25;
      end if;
      
      if tax_salary<=5000 then
       return tax_salary*15/100 - 125;
      end if;
      
      if tax_salary<=20000 then
       return tax_salary*20/100 - 375;
      end if;
      
      if tax_salary<=40000 then
       return tax_salary*25/100 - 1375;
      end if;
      
      if tax_salary<=60000 then
       return tax_salary*30/100 - 3375;
      end if;
     end;
    end get_tax;

    执行:

    select get_tax(6000) tax
    from dual;

    技术改变世界
  • 相关阅读:
    SVN为什么比Git更好
    vim的高亮查找操作
    Mac利用PD虚拟机安装Centos7
    学习MapReduce的计算原理
    hadoop-HA高可用集群部署
    HDFS命令操作和高可用
    初识hadoop及伪集群部署
    初步学习nginx
    小记--------maxwell启动失败解决
    小记--------spark资源调度机制源码分析-----Schedule
  • 原文地址:https://www.cnblogs.com/davidgu/p/2147356.html
Copyright © 2011-2022 走看看