0

我有一个包含 oracleCOLOR_HISTOGRAM列的表,它包含值。它是一个带有颜色列表和颜色频率列表的对象类型。如果我想将 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))

任何想法都受到高度赞赏。

4

1 回答 1

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 是可以的)。

或 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..
于 2013-02-15T13:43:10.110 回答