Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL: select from table with nested table

I wonder how can i make select statement from table which have a typed column ? Type of this column is defined as:

create or replace TYPE "MYCOL" as table of MYTYPE; 
create or replace TYPE "MYTYPE" as OBJECT
( myid Number, myname Varchar2);

UPD1 Table is defined as

CREATE TABLE "T_TABLE" 
   (    "ID" NUMBER NOT NULL ENABLE, "NAME" "MYCOL" )

If i select this column with select * from T_TABLE i will get this not informative result:

1, MYSCHEMA.MYCOL([MYSCHEMA.MYTYPE],[MYSCHEMA.MYTYPE])

I want just to unwrap this types.

like image 830
Igor Konoplyanko Avatar asked Dec 20 '12 12:12

Igor Konoplyanko


People also ask

What is the difference between Varray and nested table in Oracle?

A VARRAY is similar to a nested table except you must specifiy an upper bound in the declaration. Like nested tables they can be stored in the database, but unlike nested tables individual elements cannot be deleted so they remain dense.

Can we have nested tables in SQL?

In order to create a nested table, the two source tables must contain a defined relationship so that the items in one table can be related to the other table. In SQL Server Data Tools, you can define this relationship in the data source view.

What is the use of nested table in Oracle?

Understanding Nested TablesOracle stores the rows of a nested table in no particular order. But, when you retrieve the nested table into a PL/SQL variable, the rows are given consecutive subscripts starting at 1. That gives you array-like access to individual rows. PL/SQL nested tables are like one-dimensional arrays.


1 Answers

Try it like this:

select t."ID", tt.myid, tt.myname 
from "T_TABLE" t, table(t."NAME") tt;

Here is a sqlfiddle demo

like image 57
A.B.Cade Avatar answered Oct 16 '22 05:10

A.B.Cade