Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>create type t_row as object (a varchar2(10)); create type t_row_tab as table of t_row; </code></pre> <p>We will now create a function which will split the input string.</p> <pre><code>create or replace function get_number(pv_no_list in varchar2) return t_row_tab is lv_no_list t_row_tab := t_row_tab(); begin for i in (SELECT distinct REGEXP_SUBSTR(pv_no_list, '[^,]+', 1, LEVEL) no_list FROM dual CONNECT BY REGEXP_SUBSTR(pv_no_list, '[^,]+', 1, LEVEL) IS NOT NULL) loop lv_no_list.extend; lv_no_list(lv_no_list.last) := t_row(i.no_list); end loop; return lv_no_list; end get_number; </code></pre> <p>Once the function is in place we can use the table clause of sql statement to get the desired result. As desired we got multiple values returned from the function.</p> <pre><code>SQL&gt; select * from table(get_number('1,2,3,4')); A ---------- 1 3 2 4 </code></pre> <p>So now our function is simply behaving like a table. There can be a situation where you want these comma separated values to be a part of "IN" clause. </p> <p>For example :</p> <pre><code>select * from dummy_table where dummy_column in ('1,2,3,4'); </code></pre> <p>But the above query will not work as '1,2,3,4' is a string and not individual numbers. To solve this problem you can simply use following query.</p> <pre><code>select * from dummy_table where dummy_column in ( select * from table(get_number('1,2,3,4')) ); </code></pre> <p>References : <a href="http://www.oraclebin.com/2012/12/returning-multiple-values-from-function.html" rel="nofollow">http://www.oraclebin.com/2012/12/returning-multiple-values-from-function.html</a></p>
    singulars
    1. This table or related slice is empty.
    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. 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