fibonaccii
Technical User
Thank you all for being so responsive to my queries. I have another one.
I am trying to use a for loop to attain a single string into a local variable from a multiple rows with same Roll_NO. Is there an easier way to extract the rows to the string.
I have a layout of the Table XYZ as below
RN Roll_NO Amount Date
1 123456 5.00 3/3/07
2 123456 10.00 6/7/07
3 123456 20.00 8/8/07
4 123456 30.00 9/9/07
A string that tells me := 3/3/07 $5.00 (next line)
6/7/07 $10.00
....
The Code I have looks as below:
History Varchar2(800);
RowCNT NUMBER;
crlf VARCHAR(2);
BEGIN
crlf := CHR(13) || CHR(10);--(next line designator)
Create Table Temp_V as
SELECT rownum rn, Roll_NO, Amount, Due_date
FROM TABLE.DBLINK
where ROLL_NO = '123456'
and (extract(year from due_Date)) = EXTRACT(YEAR FROM sysdate)
and SUBSTR(ORIGIN,1,3) in ('FTX','ITX','STX')
order by due_date;
Begin
SELECT COUNT(*) into RowCNT
from Temp_v where ROLL_NO = '070067221660000'
For i IN 1..Rowcnt
LOOP
Select 'Date: 'Due_Date ||' '|| to_char(AMOUNT,'$9999.99') || crfl
Into History
WHERE Roll_N0 ='070067221660000'
and RowCNT = i;
end LOOP;
END;
drop table temp_v
I am trying to use a for loop to attain a single string into a local variable from a multiple rows with same Roll_NO. Is there an easier way to extract the rows to the string.
I have a layout of the Table XYZ as below
RN Roll_NO Amount Date
1 123456 5.00 3/3/07
2 123456 10.00 6/7/07
3 123456 20.00 8/8/07
4 123456 30.00 9/9/07
A string that tells me := 3/3/07 $5.00 (next line)
6/7/07 $10.00
....
The Code I have looks as below:
History Varchar2(800);
RowCNT NUMBER;
crlf VARCHAR(2);
BEGIN
crlf := CHR(13) || CHR(10);--(next line designator)
Create Table Temp_V as
SELECT rownum rn, Roll_NO, Amount, Due_date
FROM TABLE.DBLINK
where ROLL_NO = '123456'
and (extract(year from due_Date)) = EXTRACT(YEAR FROM sysdate)
and SUBSTR(ORIGIN,1,3) in ('FTX','ITX','STX')
order by due_date;
Begin
SELECT COUNT(*) into RowCNT
from Temp_v where ROLL_NO = '070067221660000'
For i IN 1..Rowcnt
LOOP
Select 'Date: 'Due_Date ||' '|| to_char(AMOUNT,'$9999.99') || crfl
Into History
WHERE Roll_N0 ='070067221660000'
and RowCNT = i;
end LOOP;
END;
drop table temp_v