• 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;

    技术改变世界
  • 相关阅读:
    CV
    Flutter 概览
    spaCy 基本使用
    图像读写、属性
    图像原理
    NLP 实战
    NLTK 相似性度量
    NLTK 停用词、罕见词
    NLTK 词干提取、词形还原
    NLTK 基本操作
  • 原文地址:https://www.cnblogs.com/davidgu/p/2147356.html
Copyright © 2020-2023  润新知