Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How Do I Parse a String into an Array or PL/SQL Table
On Wed, 11 Nov 1998 12:20:00 -0500, "Dwight Crane"
<dwight.crane_at_mci.com> wrote:
>I have a String (call it REG_RET) that is always a multiple of 12
>Lets for example say it is 48 characters long... First I Find out
>how many accounts are in the string by Dividing REG_RET by 12...
>
>Now within each set of 12 there are 5 fields:
>1-8 = account Number
>9 = flag 1
>10 = flag 2
>11= flag 3
>12= flag 4
>
>thus Field 13 Starts the cycle back over with another Account Number
>and this goes on until there are no more accounts....
>
>What I need is a way to establish each account with their flags such
>that a variable represents them
>
>ACT_NUM1(1) = account number
>ACT_NUM1(2) = Flag 1
>ACT_NUM1(3) = Flag 2
>ACT_NUM1(4) = Flag 3
>ACT_NUM1(5) = Flag 4
>
>and then the next account would be
>ACT_NUM2(1)= account number
>.
>.
>ACT_NUM2(5) = Flag 4
>
Try this.
Make a PL/SQL table of records like
type acc_rec is record (
num number := 0, f1 varchar2(1) := '', f2 varchar2(1) := '', f3 varchar2(1) := '', f4 varchar2(1) := '' );
type acc_tab is table of acc_rec index by binary_integer;
acc_num acc_tab;
and populate it with
for i in 1 .. length(REG_RET)/12 loop acc_num(i).num := substr(REG_RET,12*(i-1)+1,8); acc_num(i).f1 := substr(REG_RET,12*(i-1)+9,1); acc_num(i).f2 := substr(REG_RET,12*(i-1)+10,1); acc_num(i).f3 := substr(REG_RET,12*(i-1)+11,1); acc_num(i).f3 := substr(REG_RET,12*(i-1)+12,1);end loop;
so now
acc_num(1).num = account number 1 acc_num(1).f1 = flag 1 acc_num(1).f2 = flag 2 acc_num(1).f3 = flag 3 acc_num(1).f4 = flag 4 acc_num(2).num = account number 2 acc_num(2).f1 = flag 1 acc_num(2).f2 = flag 2
...
You can then declare variables as the record type and assign them the value of one element of the table.
l_rec1 acc_rec;
l_rec2 acc_rec;
begin
l_rec1 := acc_num(1);
l_rec2 := acc_num(2);
I hope this helps.
chris.
--
clbeck_at_us.oracle.com
Oracle Corp.
Reston, VA.
>
>I cannot find out to produce this... any help would be greatly
>appreciated!!
>
>Dwight
>
>
Received on Wed Nov 11 1998 - 14:20:31 CST