Cast to index by table [message #671867] |
Fri, 21 September 2018 01:11  |
 |
purnima1
Messages: 79 Registered: June 2014
|
Member |
|
|
Hi Experts ,
I have string which is storing number for e.g. '1,2,3'
I want to store this data in index by table. One way of doing this iterating trough string and picking each number one by one and putting it in index by table.
Could there be any query which could do this.Can we use cast
|
|
|
|
|
|
Re: Cast to index by table [message #672730 is a reply to message #671869] |
Thu, 25 October 2018 13:04  |
 |
Barbara Boehmer
Messages: 9005 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
purnima1 wrote on Thu, 20 September 2018 23:18I am trying below code but getting error
declare
v varchar2(2000):='1,2,3';
type t is table of number index by binary_integer;
tab t;
begin
select cast(v as t) from dual ;
if tab.count>0 then
dbms_output.put_line ('data converted');
end if;
end ;
SCOTT@orcl_12.1.0.2.0> declare
2 v varchar2 (2000) := '1,2,3';
3 type t is table of number index by binary_integer;
4 tab t;
5 begin
6 select regexp_substr (v, '[^,]*', rownum)
7 bulk collect
8 into tab
9 from dual
10 connect by level <= regexp_count (v, ',') + 1;
11 if tab.count > 0 then
12 dbms_output.put_line (tab.count || ' rows of data converted');
13 end if;
14 end;
15 /
3 rows of data converted
PL/SQL procedure successfully completed.
|
|
|