• oracle函数和存储过程示例


    Function:

     1 --为了使产生的uuid符合rfc 4122的标准(http://tools.ietf.org/html/rfc4122),例如:a8f662b8-6e7a-13fe-e040-970a437c6bd7
     2 --函数
     3 CREATE OR REPLACE
     4 FUNCTION get_uuid
     5 RETURN VARCHAR
     6 IS
     7 guid VARCHAR (50);
     8 BEGIN
     9 guid := lower(RAWTOHEX(sys_guid()));
    10 RETURN
    11 substr(guid,1,8)||'-'||substr(guid,9,4)||'-'||substr(guid,13,4)||'-'||substr(guid,17,4)||'-'||substr(guid,21,12);
    12 END get_uuid;

    Procedure:





     
    --功能:结转.比如当前日期为8月31日,8月是没有数据的,需将七月份的数据拷贝一份作为8月份的
    
    

    1
    create or replace procedure carryover 2 (syear IN OUT varchar2,smonth IN OUT varchar2) --注意: 参数是需要结转的年月,而非结转到的年月 3 is 4 cursor t_rows(ssyear varchar2,ssmonth varchar2) is select t.* from FYS_SCH_LVYOU2 t where t.remarks=ssmonth and t.year=ssyear; 5 tmonth varchar2(10); 6 t_row t_rows%rowtype; 7 begin 8 dbms_output.enable(100000); 9 if syear is null and smonth is null then --没有参数时,则默认上个月的年月 10 tmonth:=to_char(add_months(sysdate,-1),'yyyy-mm'); 11 syear:=substr(tmonth,1,4); 12 smonth:=substr(tmonth,6,2); 13 end if; 14 15 --dbms_output.put_line('from:'||syear||'/'||smonth); --打印 需要结转的年月 16 17 for t_row in t_rows(syear,smonth) 18 loop 19 tmonth:=to_char(add_months(to_date(t_row.year||'-'||t_row.remarks,'yyyy-mm'),1),'yyyy-mm');--结转到的年月 20 --dbms_output.put_line(' to:'||tmonth); --打印 结转到的年月 21 insert into FYS_SCH_LVYOU2 values( get_uuid(), --UUID,自定义函数,用于格式化sys_guid() 22 substr(tmonth,0,4), --year 23 t_row.classification, 24 t_row.num, 25 substr(tmonth,6,2), --month 26 t_row.remarks1, 27 t_row.remarks2, 28 t_row.remarks3, 29 t_row.remarks4, 30 t_row.remarks5, 31 t_row.remarks6, 32 t_row.remarks7, 33 t_row.remarks8, 34 t_row.remarks9, 35 t_row.remarks10 36 ); 37 end loop; 38 39 if syear='2016' then --如果是2016年之前的话,需要结转上一年的 40 syear:=to_char(to_number(syear)-1); 41 carryover(syear,smonth); --改变参数,重新调用此存储过程 42 end if; 43 44 commit; 45 exception 46 when others then rollback; 47 end;





  • 相关阅读:
    KindEditor
    java大文件(百M以上)的上传下载分享
    java大文件(百M以上)的上传下载问题
    java大文件(百M以上)的上传下载方法
    java大文件(百M以上)的上传下载思路
    飞镖靶计分题[待]
    Hive高级(1):优化(1) 执行计划/ Fetch 抓取 /本地模式
    Hadoop基础:补充:Zookeeper的目录结构
    Hadoop基础:补充:hadoop的目录结构介绍
    java 基本语法(二十):mysql JDBC URL格式各个参数详解
  • 原文地址:https://www.cnblogs.com/PheonixHkbxoic/p/5843071.html
Copyright © 2020-2023  润新知