Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This solution at first glance it looks complicated, but generally resolves any range. Solve problem with VALUEs which may be interfered with any other range.</p> <p>Firstly create sample table and insert data:</p> <pre><code>create table test_table (col_START NUMBER, col_END NUMBER, col_MAP CHAR(1)); insert into test_table(col_START, col_END, col_MAP) values(1,10,'A'); insert into test_table(col_START, col_END, col_MAP) values(11,15,'B'); insert into test_table(col_START, col_END, col_MAP) values(5,12,'C'); </code></pre> <p>Now data look like this:</p> <pre><code>START | END | MAP 1 | 10 | A 11 | 15 | B 5 | 12 | C </code></pre> <p>Now create object type:</p> <pre><code>CREATE TYPE SampleType AS OBJECT ( id number, map_string varchar2(2000) ) / CREATE TYPE SampleTypeSet AS TABLE OF SampleType / </code></pre> <p>And also create PIPELINED FUNCTION:</p> <pre><code>CREATE OR REPLACE FUNCTION GET_DATA RETURN SampleTypeSet PIPELINED IS l_one_row SampleType := SampleType(NULL, NULL); BEGIN FOR cur_data IN (select col_START, col_END, col_MAP from test_table) LOOP FOR i IN cur_data.col_START..cur_data.col_END LOOP l_one_row.id := i; l_one_row.map_string := cur_data.col_MAP; PIPE ROW(l_one_row); END LOOP; END LOOP; RETURN; END GET_DATA; / </code></pre> <p>Finally you can use simple query:</p> <pre><code>SELECT * FROM TABLE(GET_DATA()); </code></pre> <p>Or create and select it from view (if you want hide OBJECT implementation):</p> <pre><code>CREATE VIEW VIEW_ALL_DATA AS SELECT * FROM TABLE(GET_DATA()); SELECT * FROM VIEW_ALL_DATA; </code></pre> <p>Based on this my article:</p> <p><a href="http://martin-mares.cz/2010/08/oracle-db-pipelined-function/" rel="nofollow noreferrer">http://martin-mares.cz/2010/08/oracle-db-pipelined-function/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload