Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
col a heading "Col1" format 9999
col b heading "Col2" format a4
col c heading "Col3" format a4
col d heading "Col4" format a10
select col1 a, col2 b, col3 c, col4 d from mytable
/
Col1 Col2 Col3 Col4
----- ---- ---- ----------
1 A YY Oracle
1 A YY Siebel
1 A YY Sybase
2 B ZZ Oracle
2 B ZZ Siebel
2 B ZZ Sybase
2 B ZZ DB2
2 B ZZ MySQL
2 B ZZ SQL Server
2 B ZZ Informix
10 rows selected.
set linesize 200
col e heading "Strung-together Col4 Values" format a60
select col1 a, col2 b, col3 c, batchCol4(col1,col2,col3) e
from mytable
group by col1, col2, col3
/
Col1 Col2 Col3 Strung-together Col4 Values
----- ---- ---- --------------------------------------------------
1 A YY Oracle,Siebel,Sybase
2 B ZZ Oracle,Siebel,Sybase,DB2,MySQL,SQL Server,Informix
2 rows selected.
create or replace function batchCol4 (c1 number,c2 varchar2,c3 varchar2)
return varchar2
is
hold_string varchar2(4000);
separator varchar2(2);
begin
for r in (select * from mytable where c1=col1 and c2=col2 and c3=col3) loop
hold_string := hold_string||separator||r.col4;
separator := ',';
end loop;
return hold_string;
end;
/
Function created.
HOLD_STRING :=HOLD_STRING||SEPARATOR||[b]r.vendor_name[/b];
select col1 a, col2 b, col3 c, batchCol4(col1,col2,col3) e
from mytable
group by col1, col2, col3
create or replace function batchNames (SSN_In varchar2)
return varchar2
is
hold_string varchar2(4000);
separator varchar2(3);
begin
for r in (select * from test1 where SSN = SSN_IN) loop
hold_string := hold_string||separator||r.vendor_name;
separator := ' ~ ';
end loop;
return hold_string;
end;
/
Function created.
set linesize 200
col e heading "Strung-together Vendor Names" format a60
select ssn, batchNames(ssn) e
from test1
group by ssn
/
SSN Strung-together Vendor Names
--------- --------------------------------------
123456789 DOE, JANE ~ SMITH, JANE ~ THOMAS, JANE
create or replace function batchNames (SSN_In varchar2)
return varchar2
is
hold_string varchar2(4000);
separator varchar2(3) := '~';
begin
for r in (select * from test1 where SSN = SSN_IN) loop
hold_string := hold_string||separator||r.vendor_name;
end loop;
return hold_string;
end;
/
create or replace function batchNames (SSN_In varchar2)
return varchar2
is
hold_string varchar2(4000);
separator varchar2(3) := '~';
begin
for r in (select * from test1 where SSN = SSN_IN) loop
hold_string := hold_string||separator||r.vendor_name;
end loop;
return ltrim(hold_string,'~');
end;
/