Home » SQL & PL/SQL » SQL & PL/SQL » Nested table with object type (ORACLE 11g)
Nested table with object type [message #649847] Sat, 09 April 2016 03:22 Go to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
create table ss_load_trans 
(
  source_id   varchar2(20) not null,
  trans_logic trans_dtl
)  
NESTED TABLE trans_logic STORE AS trans_logic_tab


create type t_typ_trans_dtl is object
(
    trans_id     varchar2(20),
    sc_flg       char(1),
    dc_flg       char(1),
    sub_trans_id sub_trans_dtl
)    
    
CREATE TYPE trans_dtl
   AS TABLE OF t_typ_trans_dtl;
    
create  type t_typ_sub_trans_dtl is object
(
    sub_trans_id  varchar2(20),
    sc_value      varchar2(500),
    fc_value      varchar2(500),
    cc_value      varchar2(500),
    dc_value      varchar2(500)
)    

CREATE TYPE sub_trans_dtl
   AS TABLE OF t_typ_sub_trans_dtl;



create table ss_load_trans
(
  source_id   varchar2(20) not null,
  trans_logic trans_dtl
)  
NESTED TABLE trans_logic STORE AS nested_tab return as value


Executing above giving me below error
what wrong i done

Error starting at line 1 in command:
create table ss_load_trans
(
  source_id   varchar2(20) not null,
  trans_logic trans_dtl
)  
NESTED TABLE trans_logic STORE AS nested_tab return as value
Error at Command Line:1 Column:1
Error report:
SQL Error: ORA-02320: failure in creating storage table for nested table column TRANS_LOGIC
ORA-22913: must specify table name for nested table column or attribute
02320. 00000 -  "failure in creating storage table for nested table column %s"
*Cause:    An error occurred while creating the storage table for the
           specified nested table column.
*Action:   See the messages that follow for more details. If the situation
           they describe can be corrected, do so; otherwise contact Oracle
           Support.

[Updated on: Sat, 09 April 2016 03:42]

Report message to a moderator

Re: Nested table with object type [message #649848 is a reply to message #649847] Sat, 09 April 2016 03:31 Go to previous messageGo to next message
John Watson
Messages: 8935
Registered: January 2010
Location: Global Village
Senior Member
It works for me:
orclz> CREATE OR REPLACE TYPE trans_dtl AS TABLE OF VARCHAR2(30);
  2  /

Type created.

orclz>
orclz>
orclz> create table ss_load_trans
  2  (
  3    source_id   varchar2(20) not null,
  4    trans_logic trans_dtl
  5  )
  6  NESTED TABLE trans_logic STORE AS nested_tab return as value;

Table created.

orclz>
Re: Nested table with object type [message #649850 is a reply to message #649848] Sat, 09 April 2016 04:08 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
This is my entire script
My version is 11g


create table ss_load_trans 
(
  source_id   varchar2(20) not null,
  trans_logic trans_dtl
)  
NESTED TABLE trans_logic STORE AS trans_logic_tab


create type t_typ_trans_dtl is object
(
    trans_id     varchar2(20),
    sc_flg       char(1),
    dc_flg       char(1),
    sub_trans_id sub_trans_dtl
)    
    
CREATE TYPE trans_dtl
   AS TABLE OF t_typ_trans_dtl;
    
create  type t_typ_sub_trans_dtl is object
(
    sub_trans_id  varchar2(20),
    sc_value      varchar2(500),
    fc_value      varchar2(500),
    cc_value      varchar2(500),
    dc_value      varchar2(500)
)    

CREATE TYPE sub_trans_dtl
   AS TABLE OF t_typ_sub_trans_dtl;

[Updated on: Sat, 09 April 2016 04:09]

Report message to a moderator

Re: Nested table with object type [message #649854 is a reply to message #649850] Sat, 09 April 2016 12:21 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Which exact version of 11?
Re: Nested table with object type [message #649858 is a reply to message #649850] Sat, 09 April 2016 15:53 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
You need to create your tables and types in the correct order, so that each type that you reference has already been created. You need to include semicolons and slashes where appropriate. When you have multiple levels of nested tables, you need to nest multiple nested table clauses. Please see the run of the corrected code below, especially the nested table clauses in the final table creation:

NESTED TABLE trans_logic STORE AS trans_logic_tab
(NESTED TABLE sub_trans_id STORE AS sub_trans_id_tab)


SCOTT@orcl> create  type t_typ_sub_trans_dtl is object
  2  (
  3  	 sub_trans_id  varchar2(20),
  4  	 sc_value      varchar2(500),
  5  	 fc_value      varchar2(500),
  6  	 cc_value      varchar2(500),
  7  	 dc_value      varchar2(500)
  8  );
  9  /

Type created.

SCOTT@orcl> CREATE TYPE sub_trans_dtl
  2  	AS TABLE OF t_typ_sub_trans_dtl;
  3  /

Type created.

SCOTT@orcl> create type t_typ_trans_dtl is object
  2  (
  3  	 trans_id     varchar2(20),
  4  	 sc_flg       char(1),
  5  	 dc_flg       char(1),
  6  	 sub_trans_id sub_trans_dtl
  7  );
  8  /

Type created.

SCOTT@orcl> CREATE TYPE trans_dtl
  2  	AS TABLE OF t_typ_trans_dtl;
  3  /

Type created.

SCOTT@orcl> create table ss_load_trans
  2  (
  3    source_id   varchar2(20) not null,
  4    trans_logic trans_dtl
  5  )
  6  NESTED TABLE trans_logic STORE AS trans_logic_tab
  7    (NESTED TABLE sub_trans_id STORE AS sub_trans_id_tab)
  8  /

Table created.


Re: Nested table with object type [message #649976 is a reply to message #649858] Mon, 11 April 2016 22:30 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
Thank You Barbara Boehmer Smile
Re: Nested table with object type [message #650003 is a reply to message #649976] Tue, 12 April 2016 06:30 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
In the mean time i have created nested tables as mentioned below.

[b][u]Overview of my requirement is[/u] [/b]

I will have multiple source files on jurisdiction basis
for each source i will have multiple columns
for each columns have multiple transformations
for each transformation i have multiple sub transformation

so i decided to have collection tables in the below format
Suggestions if my design is wrong 

This is the first time am implementing collection with nested tables.



create or replace 
type t_typ_sub_trans_dtl is object
(
    tbl_id        varchar2(20),
    trans_id     varchar2(20),
    sub_trans_id  varchar2(20),
    sc_flg       char(1),
    dc_flg       char(1),   
    sc_value      varchar2(500),
    fc_value      varchar2(500),
    cc_value      varchar2(500),
    src_tbl_name varchar2(150),
    src_col_name varchar(150),
    trgt_tbl_name varchar2(150),
    trgt_col_name varchar2(150)
)    



create or replace 
TYPE sub_trans_dtl
   AS TABLE OF t_typ_sub_trans_dtl;



  CREATE TABLE SS_REPO.SS_LOAD_TRANS 
   (	SOURCE_ID VARCHAR2(20 BYTE) NOT NULL ENABLE, 
	TBL_ID VARCHAR2(20 BYTE), 
	TBL_NAME VARCHAR2(150 BYTE), 
	STG_TBL_NAME VARCHAR2(150 BYTE) NOT NULL ENABLE, 
	STG_COL_NAME VARCHAR2(150 BYTE) NOT NULL ENABLE, 
	PRIORITY_FLG NUMBER, 
	TRANS_ID VARCHAR2(20 BYTE), 
	SUB_TRANS_LOGIC SS_REPO.SUB_TRANS_DTL  DEFAULT SS_REPO.SUB_TRANS_DTL()
   ) 
 NESTED TABLE SUB_TRANS_LOGIC STORE AS SUB_TRANS_LOGIC_TAB



Data in table has been attached herewith.


[b]My aim is to delete and update the data by referring columns in nested table.[/b]


Here my delete statement which thrown error as

Error starting at line 28 in command:
delete  from TABLE(select a.sub_trans_logic from ss_load_trans a where a.source_id ='TH_RDSINV3' and stg_col_name='SEGMENT' ) e
  where e.trans_id='RDS3_T10' and e.sub_trans_id='RDS3_ST10' 
Error report:
SQL Error: ORA-01427: single-row subquery returns more than one row
01427. 00000 -  "single-row subquery returns more than one row"
*Cause:    
*Action:


[Updated on: Tue, 12 April 2016 06:35]

Report message to a moderator

Re: Nested table with object type [message #650006 is a reply to message #650003] Tue, 12 April 2016 07:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68658
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

NEVER use nested types for stored data.
They are complex to use.
They are hard to maintain.
They are inefficient.
They have no advantage comparing to good old relational data... above all in a relation DBMS.

Re: Nested table with object type [message #650007 is a reply to message #650006] Tue, 12 April 2016 07:40 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Michel Cadot wrote on Tue, 12 April 2016 05:24

NEVER use nested types for stored data.
They are complex to use.
They are hard to maintain.
They are inefficient.
They have no advantage comparing to good old relational data... above all in a relation DBMS.



+100
Re: Nested table with object type [message #650008 is a reply to message #650007] Tue, 12 April 2016 08:14 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
I totally agree with Michel. They are a nifty idea but in actual use very cumbersome to use and completely non-portable if you ever want to go to a different database. A standard relational table with appropriate daughter tables is MUCH easier to use and administer.
Re: Nested table with object type [message #650020 is a reply to message #650003] Tue, 12 April 2016 16:09 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
I am unable to reproduce your error, as shown below. Also, anytime that you can accomplish the same thing with standard relational tables as with objects, it seems a lot easier to not use objects. There are purposes for which they are needed, but this does not seem to be one of them.

SCOTT@orcl> COLUMN source_id	FORMAT A10
SCOTT@orcl> COLUMN stg_col_name FORMAT A19
SCOTT@orcl> SELECT a.source_id, a.stg_col_name, e.trans_id, e.sub_trans_id
  2  FROM   ss_load_trans a,
  3  	    TABLE (a.sub_trans_logic) e
  4  /

SOURCE_ID  STG_COL_NAME        TRANS_ID             SUB_TRANS_ID
---------- ------------------- -------------------- --------------------
TH_RDSINV3 RC_AO_CODE          RDS3_T1              RDS3_ST1
TH_RDSINV3 SEGMENT             RDS3_T10             RDS3_ST2
TH_RDSINV3 SEGMENT             RDS3_T10             RDS3_ST10
TH_RDSINV3 BRANCH_CODE         RDS3_T2              RDS3_ST2
TH_RDSINV3 GEID                RDS3_T3              RDS3_ST3
TH_RDSINV3 FIRST_NAME          RDS3_T5              RDS3_ST5
TH_RDSINV3 LAST_NAME           RDS3_T6              RDS3_ST6
TH_RDSINV3 MGR_GEID            RDS3_T7              RDS3_ST7
TH_RDSINV3 TEAM                RDS3_T8              RDS3_ST8
TH_RDSINV3 IS_HIGH_PERFORMANCE RDS3_T9              RDS3_ST9

10 rows selected.

SCOTT@orcl> delete from TABLE
  2    (select a.sub_trans_logic
  3  	from   ss_load_trans a
  4  	where  a.source_id ='TH_RDSINV3'
  5  	and   stg_col_name='SEGMENT' ) e
  6  where e.trans_id='RDS3_T10'
  7  and   e.sub_trans_id='RDS3_ST10'
  8  /

1 row deleted.

SCOTT@orcl> SELECT a.source_id, a.stg_col_name, e.trans_id, e.sub_trans_id
  2  FROM   ss_load_trans a,
  3  	    TABLE (a.sub_trans_logic) e
  4  /

SOURCE_ID  STG_COL_NAME        TRANS_ID             SUB_TRANS_ID
---------- ------------------- -------------------- --------------------
TH_RDSINV3 RC_AO_CODE          RDS3_T1              RDS3_ST1
TH_RDSINV3 SEGMENT             RDS3_T10             RDS3_ST2
TH_RDSINV3 BRANCH_CODE         RDS3_T2              RDS3_ST2
TH_RDSINV3 GEID                RDS3_T3              RDS3_ST3
TH_RDSINV3 FIRST_NAME          RDS3_T5              RDS3_ST5
TH_RDSINV3 LAST_NAME           RDS3_T6              RDS3_ST6
TH_RDSINV3 MGR_GEID            RDS3_T7              RDS3_ST7
TH_RDSINV3 TEAM                RDS3_T8              RDS3_ST8
TH_RDSINV3 IS_HIGH_PERFORMANCE RDS3_T9              RDS3_ST9

9 rows selected.

Re: Nested table with object type [message #650163 is a reply to message #650020] Sun, 17 April 2016 23:55 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
Thanks for the suggestions ... practically i felt the hard maintenance on this implemetation.
So i changed to normal RDBMS tables.

Thanks a lot Smile

[Updated on: Mon, 18 April 2016 00:18] by Moderator

Report message to a moderator

Re: Nested table with object type [message #650274 is a reply to message #650020] Thu, 21 April 2016 06:38 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
Can i ask in what situation i can go for nested collection implementation?
Re: Nested table with object type [message #650275 is a reply to message #650274] Thu, 21 April 2016 06:43 Go to previous messageGo to next message
John Watson
Messages: 8935
Registered: January 2010
Location: Global Village
Senior Member
Other people may disagree, but I would say that the purpose of these complex data types is really just to make use of some development tools easier. If you have to use an OO language, perhaps collections will make life easier for your programmers. Perhaps.

Re: Nested table with object type [message #650289 is a reply to message #650275] Thu, 21 April 2016 13:23 Go to previous message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
I don't see any benefit to using objects for general data storage. Objects are required for things like user-defined aggregate functions and pipelined table functions.

Previous Topic: Error when create policy after create view. What is the problem?
Next Topic: Dbms_schedule
Goto Forum:
  


Current Time: Sat Jun 01 06:14:53 CDT 2024