Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Geetika .

Asked: September 26, 2016 - 12:20 pm UTC

Last updated: July 15, 2021 - 1:42 pm UTC

Version: 12c

Viewed 50K+ times! This question is

You Asked

I have created a type

below is the code of the type
create or replace type tt_name as table of varchar2(250);


Now I want to perform select on this type in a plsql code

select listagg(column_name,';') within group(order by column_name) into varchar_variable
from table(tt_name);

I don't know what should I write in place of column_name.
In case of a table type which is based on some other type column_name is the element name of the type on which table type is created. But what should be the the column name in this case.

Thanks!!



and Chris said...

Oooh, so close. The name of the "column" in the array is column_value:

create or replace type tt_name as table of varchar2(250);
/

declare
  l varchar2(1000);
  arr tt_name := tt_name ('abc', 'def', 'ghi');
begin
  select listagg(column_value, ';') within group (order by column_value) 
  into   l 
  from   table(arr);
  
  dbms_output.put_line(l);
end;
/

abc;def;ghi

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, September 26, 2016 - 7:34 pm UTC

Thanx for responding and solving so many plsql problem. Answer by you are always correct and useful.
Chris Saxon
September 27, 2016 - 12:30 am UTC

glad we could help

What to do if the table type has more than one column?

Mano, May 21, 2018 - 1:36 pm UTC

Hi. What to do if the table type has more than one column? Is there a way to use column_name in this scenario?
Chris Saxon
May 22, 2018 - 1:52 pm UTC

Reference them by attribute name:

create or replace type obj as object (
  x int, y int
);
/

create or replace type obj_arr as table of obj;
/

declare
  v obj_arr;
begin

  v := obj_arr ( obj ( 1, 2 ), obj ( 3, 4 ) );
  
  for rws in (
    select t.x, t.y from table ( v ) t
  ) loop
    dbms_output.put_line ( rws.x || ' ' || rws.y );
  end loop;

end;
/

1 2
3 4

Access all column of a table in to a field.

Raja, July 15, 2021 - 1:34 pm UTC

create or replace TYPE INP_OBJ AS OBJECT

( NAME VARCHAR2(9 CHAR)

,ADDRESS1 VARCHAR2(50 CHAR)

,ADDRESS2 VARCHAR2(50 CHAR)

,CITY VARCHAR2(5 CHAR) );


create or replace TYPE INP-TAB AS TABLE OF INP_OBJ ;

I have 3 rows in the inp-tab and I want to move 2nd row of inp-tab to a blob field (say L-blob-field ).

I dont want to concatenate field by field and move it to l-blob-field. is there a way move the whole record (all column) in to a blob field ?

Note: In actual input-table i have 30 column and i need to move the it to blob field and insert it to a error table incase of failure.
Chris Saxon
July 15, 2021 - 1:42 pm UTC

You've already submitted this on another question; please only add reviews in one place - and make them relevant to the original question!

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library