set serveroutput on
declare
cursor cemp(dno number) is select ename from emp where empno=dno;
pename emp.ename%type;
begin
open cemp(10);
LOOP
fetch cemp into pename;
exit when cemp%notfound;
dbms_output.put_line(pename);
end loop;
close cemp;
end;
/
為啥我沒(méi)有結(jié)果
declare
cursor cemp(dno number) is select ename from emp where empno=dno;
pename emp.ename%type;
begin
open cemp(10);
LOOP
fetch cemp into pename;
exit when cemp%notfound;
dbms_output.put_line(pename);
end loop;
close cemp;
end;
/
為啥我沒(méi)有結(jié)果
2017-06-01
光標(biāo)又叫做游標(biāo),代表了一個(gè)結(jié)果集。好比是jdbc中的Result Set集
2017-06-01
代碼段三:
close emp_cursor;
dbms_output.put_line('漲工資人數(shù) 工資總額');
dbms_output.put_line(rpad(countsum,8,' ')||' '||rpad(totalsal,8,' '));
end;
close emp_cursor;
dbms_output.put_line('漲工資人數(shù) 工資總額');
dbms_output.put_line(rpad(countsum,8,' ')||' '||rpad(totalsal,8,' '));
end;
2017-05-28
代碼段二:
loop
exit when totalsal>50000;
fetch emp_cursor into cempno,csal ;
exit when emp_cursor%notfound;
if totalsal+csal*0.1<=50000 then --這一句很關(guān)鍵,如果沒(méi)有這個(gè)判斷的話,總工資可能會(huì)超過(guò)5萬(wàn)。
update emp set sal=sal*1.1 where empno=cempno;
countsum:=countsum+1;
totalsal:=totalsal+csal*0.1;
end if;
end loop;
commit;
loop
exit when totalsal>50000;
fetch emp_cursor into cempno,csal ;
exit when emp_cursor%notfound;
if totalsal+csal*0.1<=50000 then --這一句很關(guān)鍵,如果沒(méi)有這個(gè)判斷的話,總工資可能會(huì)超過(guò)5萬(wàn)。
update emp set sal=sal*1.1 where empno=cempno;
countsum:=countsum+1;
totalsal:=totalsal+csal*0.1;
end if;
end loop;
commit;
2017-05-28
由于一次不能發(fā)表超過(guò)300個(gè)字,所以只能分散發(fā)布了:
代碼段一:
set serveroutput on;
declare
cursor emp_cursor is
select empno,sal from emp order by sal asc;
countsum number :=0;
totalsal emp.sal%type;
cempno emp.empno%type;
csal emp.sal%type;
begin
select sum(sal) into totalsal from emp;
open emp_cursor;
代碼段一:
set serveroutput on;
declare
cursor emp_cursor is
select empno,sal from emp order by sal asc;
countsum number :=0;
totalsal emp.sal%type;
cempno emp.empno%type;
csal emp.sal%type;
begin
select sum(sal) into totalsal from emp;
open emp_cursor;
2017-05-28
按照老師的思路,我編寫(xiě)了如下代碼:修正了總工資超過(guò)五萬(wàn)的小bug,運(yùn)行之后沒(méi)有問(wèn)題,各位可以借鑒一下,如果有更好的方法歡迎交流,謝謝:
2017-05-28
我用sqldeveloper建立sys、system等可以連接,但是scott賬戶不行,提示scott賬戶鎖定??墒俏以赑L/SQL上可以連接,scott的確也解鎖了、
2017-05-25
loop
exit when countsal > 50000;
fetch cemp into pempno,psal;
exit when cemp%notfound;
exit when (countsal+psal*0.1) > 50000;
exit when countsal > 50000;
fetch cemp into pempno,psal;
exit when cemp%notfound;
exit when (countsal+psal*0.1) > 50000;
2017-05-08