oracle函数返回数组

create or replace type type_table as object(
ID NUMBER,
NAME NUMBER);

create or replace type type_array as TABLE OF type_table;


CREATE OR REPLACE FUNCTION TEST_LCX RETURN TYPE_ARRAY IS
  RESULT    TYPE_ARRAY;
  TABLE_LCX TYPE_TABLE;
BEGIN
  RESULT := TYPE_ARRAY();
  FOR V_ROW IN (SELECT 1 ID, 2 NAME
                  FROM DUAL
                UNION ALL
                SELECT 1 ID, 2 NAME FROM DUAL) LOOP
    TABLE_LCX      := TYPE_TABLE(0, 0);
    TABLE_LCX.ID   := V_ROW.ID;
    TABLE_LCX.NAME := V_ROW.NAME;
    RESULT.EXTEND();
    RESULT(RESULT.LAST) := TABLE_LCX;
  END LOOP;
  RETURN(RESULT);
END TEST_LCX;



CREATE OR REPLACE FUNCTION TEST_LCX1 RETURN TYPE_TABLE IS
  RESULT TYPE_TABLE;
BEGIN
  RESULT := TYPE_TABLE(0, 0);
  SELECT 1 ID, 2 NAME  FROM DUAL;
  RETURN(RESULT);
END TEST_LCX1;

你可能感兴趣的:(Oracle函数)