Orcale创建函数(function)

 Oraclec创建函数的语法规则

   create or replace function  函数名 (参数名1 参数类型,参数名2 参数类型)  return number  is

   Result number ;

 begin 

          return (Result);

  end;

 例子 : 根据工号返回城市的函数

    

   调用函数

   

  •  根据日期,返回时上半年还是下半年(上半年1,下半年2)
    --根据日期获取上半年还是下半年
    CREATE OR REPLACE FUNCTION getYearHalf(iDate Date)
    RETURN number is
    month char(2);
    half number;
    begin 
      select to_char(iDate,'MM') into month from dual;
      half :=to_number(month) ;
      if half>6 then 
        half:=2;
        else 
          half:=1;
          end if;
      return half;
      end;
    View Code

 

   

 

posted @ 2016-05-18 17:24  Blue眼泪2016  阅读(439)  评论(0编辑  收藏  举报