2022 0414

--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;   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值