亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我insert之后就直接掛起了

為什么我insert之后就直接掛起了,需要手動commit,后面的語句都不執行了


正在回答

1 回答

declare

cursor cdept is select deptno from dept;

pdeptno dept.deptno%type;

cursor cemp(dno number) is select sal from emp where deptno = dno;

psal emp.sal%type;

count1 int;

count2 int;

count3 int;

totalMon number := 0;

flag number;

begin

? open cdept;

? --外層循環

? loop

? ? fetch cdept into pdeptno;

? ? exit when cdept%notfound;

? ? --判斷部門是否存在,如果部門不存在直接退出所有循環

? ? select count(1) into flag from emp where deptno = pdeptno;

? ? if flag = 0 then return;

? ? end if;

? ? --第一層循環內給變量賦值為0,保證每次內層循環的計數器都從零開始(必須要寫外層循環內,內層循環外)

? ? count1 := 0;

? ? count2 := 0;

? ? count3 := 0;

? ? open cemp(pdeptno);

? ? loop

? ? ? select sum(sal) into totalMon from emp where deptno = pdeptno;

? ? ? fetch cemp into psal;

? ? ? exit when cemp%notfound;

? ? ? if psal <3000 then count1 := count1+1;

? ? ? elsif psal <6000 then count2 := count2+1;

? ? ? else count3 := count3+1;

? ? ? end if;

? ? end loop;

? ? close cemp;

? ? --保存到msg表

? ? insert into msg values(pdeptno,count1,count2,count3,totalMon);

? ? --輸出

? ? --dbms_output.put_line('部門:'||pdeptno||' 3000以下為:'||count1||' 3000-6000為:'||count2||' 6000以上為:'||count3||' 總額為:'||totalMon);

? end loop;

? close cdept;

? commit;

? dbms_output.put_line('統計完成');

end;

/


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么我insert之后就直接掛起了

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號