-----ip转数字 计算ip范围-----
create or replace function ip2number(ip varchar2)
return number
is
ip_num_hex varchar2(80);
begin
if (regexp_like(ip, '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$')) then
ip_num_hex := lpad(trim(to_char(regexp_replace(ip, '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', '\1'), 'XX')),2,'0') ||
lpad(trim(to_char(regexp_replace(ip, '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', '\2'), 'XX')),2,'0') ||
lpad(trim(to_char(regexp_replace(ip, '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', '\3'), 'XX')),2,'0') ||
lpad(trim(to_char(regexp_replace(ip, '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', '\4'), 'XX')),2,'0');
return to_number(ip_num_hex, 'XXXXXXXX');
else
return -1;
end if;
exception
when others then
return -99999999999;
end;
-----分组后行转列 有时会有长度超出问题-----
CREATE OR REPLACE FUNCTION func_strcat(input varchar2)
RETURN varchar2 -- 返回值
PARALLEL_ENABLE AGGREGATE USING strcat_type; --使平行累加
-----ID串转name串-----
CREATE OR REPLACE FUNCTION func_idsTonames(id_data in NVARCHAR2,
thetable in NVARCHAR2,
thename in NVARCHAR2)
RETURN NVARCHAR2 AS
TYPE refcursor IS REF CURSOR;
v_cursor refcursor;
v_name NVARCHAR2(100);
v_result NVARCHAR2(1000);
v_id_dada NVARCHAR2(1000);
v_SQL VARCHAR2(1000);
BEGIN
v_id_dada := REPLACE(id_data, ',', ''',''');
v_id_dada := '''' || v_id_dada || '''';
v_result := '';
v_SQL := 'SELECT ' || thename || ' FROM ' || thetable ||
' WHERE groupID IN (' || v_id_dada || ')';
-- 打开游标.
OPEN v_cursor FOR v_SQL;
LOOP
-- 填充数据.
FETCH v_cursor
INTO v_name;
-- 无数据时 退出循环.
EXIT WHEN v_cursor%NOTFOUND;
v_result := v_result || v_name || ',';
END LOOP;
-- 关闭游标.
CLOSE v_cursor;
v_result := TRIM(BOTH ',' FROM v_result);
RETURN v_result;
END;