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;

    技术改变世界
  • 相关阅读:
    hadoop生态--ElasticSearch--ES操作
    Haoop生态--ElasticSeaarch(1)--ES预备知识(全文检索的概念、Lucence、倒排索引)
    hadoop生态--Hive(2)--Hive的使用方式
    hadoop生态--Zookeeper
    gsoap使用
    set容器
    如何杀死defunct进程
    关于多态
    数组类型与函数指针基本语法知识
    syslog日志
  • 原文地址:https://www.cnblogs.com/davidgu/p/2147356.html
Copyright © 2011-2022 走看看