1

i have a code for generating number :

create or replace package pk1 as

type t1 is table of number;

function p(x number) return t1 pipelined;

end pk1;

create or replace package body  pk1 is

function p(x number) return t1 pipelined is

begin

for i in 1..x loop

PIPE ROW(i);

    END LOOP;

    RETURN;

  END f1;

END pkg1;

this can also be done if a create an object and a collection for that object(table) and

use extend function and insert the value in the object

what would be the difference .

CREATE TYPE t_tf_row AS OBJECT (

  id           NUMBER,

  description  VARCHAR2(50)

);


CREATE TYPE t_tf_tab IS TABLE OF t_tf_row;

CREATE OR REPLACE FUNCTION get_tab_tf (p_rows IN NUMBER) RETURN t_tf_tab AS

  l_tab  t_tf_tab := t_tf_tab();

BEGIN

  FOR i IN 1 .. p_rows LOOP

    l_tab.extend;

    l_tab(l_tab.last) := t_tf_row(i, 'Description for ' || i);

  END LOOP;

  RETURN l_tab;

END;
sqlab
  • 6,412
  • 1
  • 14
  • 29
Ashish sinha
  • 148
  • 2
  • 9
  • If you want to avoid the overhead of either, you can always just use a connect_by loop: `select level from dual connect by level <= :x` – Starfighter Feb 07 '14 at 22:21

0 Answers0