ORCAL上机7-1

--查询emp表中员工编号信息

 SQL> select empno from scott.emp;

1.存储过程的创建及使用

--存储过程的创建及使用
--(1)创建一个存储过程query_emp,该过程将根据提供的empno列的值检索雇员的ename和sal。
Create or replace procedure query_emp
(v_empno in scott.emp.empno%type,
v_ename out scott.emp.ename%type,
v_sal out scott.emp.sal%type)
is
begin 
select ename,sal into v_ename,v_sal from scott.emp
where empno = v_empno;
end;

2.显示错误

--(2)显示错误
show errors

3.调用存储过程

--3)调用过程-查询编号是7934员工的姓名,工资
var p_name varchar2(10)
var p_sal number 
exec query_emp(7934,:p_name,:p_sal)
print p_name
print p_sal
--调用过程-查询编号是****的员工的姓名和工资
declare
p_ename scott.emp.ename%type;
p_sal scott.emp.sal%type;
p_empno scott.emp.empno%type:=&pp;
begin
query_emp(p_empno,p_ename,p_sal);
dbms_output.put_line(p_ename||' '||p_sal);
end;

4.使用存储过程删除某员工信息

--4)开除某个员工,从scott.emp表中删除指定编号(empno)的员工记录,编写存储过程(fire_emp)实现。
create or replace procedure frie_emp(
p_empno in scott.emp.empno%type)
is 
begin 
delete from scott.emp
where empno=p_empno;
end;
/
--在一个无名中调用(frie_emp)
declare
v_empno number:= 7839;
begin
frie_emp(v_empno);
dbms_output.put_line('已开除编号为7839的员工');
end;
/

 

5.函数的创建及使用

--5)函数的创建及使用
--创建函数get_sal,实现通过输入编号获得其对应的工资。
create or replace function get_sal(v_emp_no in scott.emp.empno%type)
return scott.emp.sal%type
is
v_emp_sal scott.emp.sal%type:=0;
begin
select sal 
into v_emp_sal
from scott.emp
where empno=v_emp_no;
return(v_emp_sal);
end get_sal;
--在无名块中调用函数(get_sal),获取编号是7782的员工的工资
variable v_sal number
declare 
v_empno number:=7782;
begin
:v_sal:=get_sal(v_empno);
end;
/
--输出变量值
print v_sal
--查看过程、函数的源代码
select text from user_source
where name='GET_SAL';

6.触发器的创建及使用

--6)触发器的创建和使用
--修改表结构,增加一列(income)
alter table scott.emp add income number(7,2);
desc scott.emp

  • 10
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值