Oracle PACKAGE 多参数合并输入,游标返回 ,查看游标返回记录集

CREATE OR REPLACE TYPE Varchar2Varray IS VARRAY(100) of VARCHAR2(40);
/

CREATE OR REPLACE FUNCTION sf_split_string (string VARCHAR2, substring VARCHAR2) RETURN Varchar2Varray IS
  len integer := LENGTH(substring);
  lastpos integer := 1 - len;
  pos integer;
  num integer;
  i integer := 1;
  ret Varchar2Varray := Varchar2Varray(NULL);
BEGIN
  LOOP
    pos := instr(string, substring, lastpos + len);
    IF pos > 0 THEN        --found
      num := pos - (lastpos + len);
    ELSE                --not found
      num := LENGTH(string) + 1 - (lastpos + len);
    END IF;

    IF i > ret.LAST THEN
      ret.EXTEND;
    END IF;

    ret(i) := SUBSTR(string, lastpos + len, num);

    EXIT WHEN pos = 0;
    lastpos := pos;
    i := i + 1;
  END LOOP;

  RETURN ret;
END;
/


CREATE OR REPLACE PACKAGE FirstPage is
 type outlist is ref cursor;
  Procedure p_get( IMP  in varchar2, return_list out outlist );
END FirstPage;

/
CREATE OR REPLACE package body FirstPage is
Procedure p_get( IMP in varchar2, return_list out outlist )
is
begin
      open return_list for
      select * from (
SELECT ROI.ROM_ID, ROI.IM_ID
FROM GML_ROITEM roi
WHERE ROI.ROM_ID IN (select * from table (cast (
 sf_split_string(IMP, ',') as Varchar2Varray) ))
UNION
SELECT ROI.ROM_ID, 99999999999 TEST
FROM GML_ROITEM roi
WHERE ROI.ROM_ID IN (select * from table (cast (
 sf_split_string(IMP, ',') as Varchar2Varray) ))
GROUP BY ROI.ROM_ID
)
ORDER BY ROM_ID, IM_ID;
end ;
end FirstPage;

/

--可查看PACKAGE 返回的结果

VAR c refcursor;
execute RYQ.FIRSTPAGE.p_get('2380,2361',:c)
print c;

 

你可能感兴趣的:(package)