DECLARE
CURSOR A_CUR IS
SELECT QTY,COUNT(QTY) COUNT_NUM FROM A
WHERE ITEM = 'A' GROUP BY ITEM,QTY ;
I NUMBER;
A VARCHAR2(20);
B VARCHAR2(20);
C VARCHAR2(80);
BEGIN
I := 1;
FOR A_REC IN A_CUR LOOP
A := A||I;
B := B||I;
A := A_REC.QTY ;
B := A_REC.COUNT_NUM ;
I := I + 1 ;
C := C||A||'*'||B||'.' ;
END LOOP;
Set serveroutput On;
Declare
str Varchar2(20):=Null;
Cursor c1 Is
Select qty,Count(item) num
From a
Group By qty;
Begin
For emp In c1 Loop
If(str Is Null) Then
str :=emp.qty||'*'||emp.num;
Else
str:=str||'+'||emp.qty||'*'||emp.num;
End If;
End Loop;
dbms_output.put_line(str);
End;
俺用一个SQL语句实现不了.就写了一长串.楼上的差不多.