Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column Name of PL/SQL Table-Type

I have a PL/SQL table-type/associative-array in Oracle

CREATE OR REPLACE TYPE STRING_TBL IS TABLE OF VARCHAR2(3000);

on which I can perform select queries like this

...
strings STRING_TBL;
...
SELECT * FROM TABLE(strings);

But what is the column name of that one column in the result set? That is, what would I need to put into <name_of_only_column> to make this query work:

SELECT rowid, p.<name_of_only_column>
FROM TABLE(strings) p;

Alternatively, if I can't do that, is there any way to alias that one column through a subselect in Oracle?

like image 672
Dexter Avatar asked Sep 20 '13 07:09

Dexter


2 Answers

But what is the column name of that one column in the result set?

Pseudocolumn named column_value.

-- nested table schema object type
create type t_list as table of number


select column_value
  from table(T_List(1,2,3))

  COLUMN_VALUE
------------
           1 
           2 
           3 

Note: In this case it's not allowed to use rowid pseudocolumn, simply because in-memory nested table does not have one.

like image 97
Nick Krasnov Avatar answered Sep 18 '22 21:09

Nick Krasnov


It's column_value, the following should work:

SELECT rowid, p.column_value
FROM TABLE(strings) p;
like image 21
a_horse_with_no_name Avatar answered Sep 18 '22 21:09

a_horse_with_no_name