Tuesday, September 16, 2008

PL/SQL Loop Creates Pivot

Declare
All_Depts Varchar2 (50) := '';

Cursor c_Loc Is
-----------------------------------
-- don't put ',' in front of 1st
-----------------------------------
Select Case When Rownum <> 1 Then ',' End
||
Loc
As
Loc
From Dept;

Begin
For c_Each In c_Loc
Loop
All_Depts := All_Depts || c_Each.Loc;
End Loop;

Dbms_Output.Put_Line (All_Depts);
End;
/

1 comment: