Oracle 自定义函数

来源:互联网 发布:阿里云mx记录值 编辑:程序博客网 时间:2024/05/16 04:31



create or replace function ipmsdw.fun_dw_o_max_stat_time(v_dw_table_name in varchar2)  return varchar2 is  o_table_max_time_record varchar2(32767);        TYPE ref_cursor_type IS REF CURSOR;     --定义动态游标  v_o_table_name  ipmsdw.dw_o_relation.o_table_name%type;  v_sql           varchar(1000);  v_max_stat_time date;  v_str           varchar(1000);  cur_o_tables ref_cursor_type;begin  v_sql := 'select o_table_name from dw_o_relation where  dw_table_name= ''' ||           v_dw_table_name || '''';      --拼接sql  open cur_o_tables for v_sql;    --打开游标  loop    fetch cur_o_tables      into v_o_table_name;    exit when cur_o_tables%notfound;      v_sql := ' select max(stat_time)  from   ' || v_o_table_name;  --       execute immediate v_sql      into v_max_stat_time;      v_str := to_char(sysdate, 'yyyy-mm-dd hh24:mm:ss') || '  ' ||             v_o_table_name || '  ' || v_max_stat_time  || chr(13)||chr(10);      o_table_max_time_record := o_table_max_time_record || v_str;    dbms_output.put_line(v_str);    end loop;  close cur_o_tables;  return o_table_max_time_record;  --返回值exception    --异常处理  when too_many_rows then    dbms_output.put_line('返回记录超过一行');    close cur_o_tables;  when no_data_found then    dbms_output.put_line('无数据记录');    close cur_o_tables;  end;


参考链接:https://www.cnblogs.com/alsf/p/6285558.html

参考链接:https://www.cnblogs.com/superjt/p/4274329.html

参考链接:http://www.cnblogs.com/defias/p/3334098.html#tip2.4.2.3

原创粉丝点击