--1、输入一个部门编号,给emp表中该部门的每个员工增加100元奖金,
--使用隐式游标输出多少个人的奖金受到影响。
declare
begin
update emp e set sal = e.sal + 100;
if sql%found then
dbms_output.put_line('工资修改成功,影响行数'||sql%rowcount);
else
dbms_output.put_line('没有修改');
end if;
rollback;
end;
````sql
--2、使用隐式游标,输出10部门员工的工资、奖金、总收入。
declare
begin
for row in (select * from emp e where e.deptno=10) loop
dbms_output.put_line('员工工资是:'||row.sal||'奖金是:'
||nvl(row.comm,0)||'总收入是'||row.sal+nvl(row.comm,0));
end loop;
end;
--3、输入一个部门编号,使用隐式游标输出该部门员工的工资、
--奖金、总收入。如果部门编号不存在,则输出“错误的部门编号”。
declare
eno emp.deptno%type;
c number;
begin
eno := &输入部门编号;
select count(1) into c from emp e where eno=e.deptno;
if c = 0 then
dbms_output.put_line('错误的部门编号');
else
for row in (select * from emp e where eno=e.deptno) loop
dbms_output.put_line('员工的工资:'||row.sal);
end loop;
end if;
end;
declare
--声明游标
cursor c1 is select * from emp;
--声明行变量
v_row emp%rowtype;
begin
open c1; --打开游标
loop --循环
fetch c1 into v_row;--提取信息到行变量中
exit when c1%notfound;--没有数据时立即退出
dbms_output.put_line(v_row.ename);--操作
end loop;--停止循环
close c1;--关闭
end;
````sql
/*4、输入一个部门编号,给emp表中该部门的每个员工增加100元奖金,
输出多少个人的奖金受到影响。使用隐式游标输出该部门员工的工资、
奖金、总收入。如果部门编号不存在,则输出“错误的部门编号”。*/
declare
dno emp.deptno%type;
c number;
begin
dno := &输入部门编号;
update emp e set comm = nvl(e.comm,0) + 100;
if sql%found then
dbms_output.put_line('奖金受到影响的人数'||sql%rowcount);
end if;
````sql
declare
v1 number;
begin
--select sal into v1 from emp;
select 1/0 into v1 from emp;
dbms_output.put_line(v1);
exception
when too_many_rows then dbms_output.put_line('错误');
when others then dbms_output.put_line('you can you up');
end;
2022 0414
最新推荐文章于 2024-09-27 21:41:13 发布