2013-02-15 1 views
0

oracle COLOR_HISTOGRAM 열을 포함하는 테이블이 있습니다.이 테이블에는 값이 들어 있습니다. colorlist와 colorfrequencielist를 가진 객체 유형입니다. SI_COLORS를 테이블에 삽입하려면 어떻게해야합니까? 오라클 객체 속성에 도달하는 방법은 무엇입니까?

나는 할 수는

--CREATE OR REPLACE TYPE colorsList AS VARRAY(100) OF SI_Color; 
--CREATE OR REPLACE TYPE colorFrequenciesList AS VARRAY(100) OF DOUBLE PRECISION; 


ORDSYS.SI_COLORHISTOGRAM(
ORDSYS.COLORSLIST(
ORDSYS.SI_COLOR(195,157,133), 
ORDSYS.SI_COLOR(226,223,215), 
ORDSYS.SI_COLOR(191,154,131), 
ORDSYS.SI_COLOR(139,94,61), 
ORDSYS.SI_COLOR(221,40,43), 
ORDSYS.SI_COLOR(85,47,30), 
ORDSYS.SI_COLOR(237,45,51), 
ORDSYS.SI_COLOR(190,60,47), 
ORDSYS.SI_COLOR(66,53,49), 
ORDSYS.SI_COLOR(145,66,63), 
ORDSYS.SI_COLOR(192,115,111), 
ORDSYS.SI_COLOR(64,50,46), 
ORDSYS.SI_COLOR(178,151,123), 
ORDSYS.SI_COLOR(178,153,129), 
ORDSYS.SI_COLOR(170,140,114), 
ORDSYS.SI_COLOR(174,150,124), 
ORDSYS.SI_COLOR(146,118,106), 
ORDSYS.SI_COLOR(189,168,145), 
ORDSYS.SI_COLOR(190,171,148), 
ORDSYS.SI_COLOR(144,71,57), 
ORDSYS.SI_COLOR(86,45,26), 
ORDSYS.SI_COLOR(193,109,80), 
ORDSYS.SI_COLOR(145,138,136), 
ORDSYS.SI_COLOR(130,121,120), 
ORDSYS.SI_COLOR(115,80,72), 
ORDSYS.SI_COLOR(186,50,37), 
ORDSYS.SI_COLOR(193,171,149), 
ORDSYS.SI_COLOR(0,0,0)), 
ORDSYS.COLORFREQUENCIESLIST(99014.1,67706.4,38034.6,28478.2,5075.64,3302.56,2429.49,856.41,638.462,560.256,520.513,476.923,439.744,296.154,247.436,232.051,194.872,138.462,123.077,110.256,82.0513,75.641,62.8205,51.2821,46.1538,43.5897,32.0513,0)) 

어떤 생각이 매우 감사 이러한 값을 포함하는 두 가지 유형 declated.

답변

1

이 같은 SI_COLOR 값을 참조 할 수 있습니다 :

SQL> create table foo(r integer, b integer, g integer); 

Table created. 

SQL> insert into foo 
    2 select cl.redvalue, cl.bluevalue, cl.greenvalue 
    3 from tbl t, table(t.color_histogram.SI_COLORSLIST) cl; 

28 rows created. 

SQL> select * from foo; 

     R   B   G 
---------- ---------- ---------- 
     195  133  157 
     226  215  223 
     191  131  154 
     139   61   94 
     221   43   40 
...etc.. 

을 모두 배열에 대해 :

SQL> create table foo(r integer, b integer, g integer, freq number); 

Table created. 

SQL> insert into foo 
    2 select cl.redvalue, cl.bluevalue, cl.greenvalue, fl.freq 
    3 from (select t.rowid rid, cl.redvalue, cl.bluevalue, cl.greenvalue, rownum r 
    4   from tbl t, table(t.color_histogram.SI_COLORSLIST) cl) cl 
    5   inner join (select t.rowid rid, rownum r, fl.column_value freq 
    6      from tbl t, table(t.color_histogram.si_frequencieslist) fl) fl 
    7     on fl.rid = cl.rid 
    8    and fl.r = cl.r; 

28 rows created. 

SQL> select * from foo; 

     R   B   G  FREQ 
---------- ---------- ---------- ---------- 
     195  133  157   1 
     226  215  223   2 
     191  131  154   3 
     139   61   94   4 
..etc.. 

(그들은 ROWNUM이 확인 그래서 우리는 순서에 의존 할 수 varrays만큼).

또는 PL/SQL

:

SQL> begin 
    2 for r_row in (select t.color_histogram 
    3     from tbl t) 
    4 loop 
    5  for idx in 1..r_row.color_histogram.si_colorslist.count 
    6  loop 
    7  insert into foo 
    8     (r, g, b, freq) 
    9  values (r_row.color_histogram.si_colorslist(idx).redvalue, 
10    r_row.color_histogram.si_colorslist(idx).greenvalue, 
11    r_row.color_histogram.si_colorslist(idx).bluevalue, 
12    r_row.color_histogram.si_frequencieslist(idx)); 
13  end loop; 
14 end loop; 
15 end; 
16/

PL/SQL procedure successfully completed. 

SQL> select * from foo; 

     R   B   G  FREQ 
---------- ---------- ---------- ---------- 
     195  133  157   1 
     226  215  223   2 
     191  131  154   3 
     139   61   94   4 
     221   43   40   5 
     85   30   47   6 
etc.. 
+0

덕분에 잘 작동 :) 나는 PL/SQL로 복잡. – Greg

+0

colorFrequenciesList와 함께 작동하는지 궁금합니다. – Greg

+0

@Greg는 테이블 항목에서't.color_histogram.COLORFREQUENCIESLIST'를 사용할 수 있도록 허용합니다. 또는 같은 시간에 RGB + assoc 주파수를 모두 동시에 저장하고 싶습니까? – DazzaL

관련 문제