oracle数据库1、用带参数的游标实现查询某部门中员工的姓名和工资,并输出。(实参为:“财务部”)2. 用存储过程实现:根据给定的学生的学号和课程号返回该学生的姓名和选课成绩。3. 创建一个存储
1、用带参数的游标实现查询某部门中员工的姓名和工资,并输出。(实参为:“财务部”)2. 用存储过程实现:根据给定的学生的学号和课程号返回该学生的姓名和选课成绩。3. 创建一个存储函数:根据给定的部门,返回该部门员工的工资总和。
·
1、用带参数的游标实现查询某部门中员工的姓名和工资,并输出。(实参为:“财务部”)
2. 用存储过程实现:根据给定的学生的学号和课程号返回该学生的姓名和选课成绩。
3. 创建一个存储函数:根据给定的部门,返回该部门员工的工资总和
1、用带参数的游标实现查询某部门中员工的姓名和工资,并输出。(实参为:“财务部”)
declare
cursor se_cursor(depname dept.dname%type:=&depname)is select ename,sal
from system.emp,system.dept where dept.dname=depname and emp.deptno=dept.deptno;
se se_cursor%rowtype;
begin
open se_cursor;
loop
fetch se_cursor into se;
exit when se_cursor%notfound;
dbms_output.put_line('姓名:'||se.ename||'工资:'||se.sal);
end loop;
close se_cursor;
end;
2. 用存储过程实现:根据给定的学生的学号和课程号返回该学生的姓名和选课成绩。
//定义触发器
create or replace procedure returns(
stno in system.grade.sno%type,//定义输入变量
ctno in system.grade.cno%type,
stname out system.student.sname%type,//定义输出变量
stg out system.grade.grade%type)is
begin
select sname,grade into stname,stg from system.student,system.grade
where grade.sno=stno and grade.cno=ctno and system.student.sno=stno;
dbms_output.put_line(stname||stg);
end returns;
//调用
declare
stno system.grade.sno%type:=&stno;
ctno system.grade.cno%type:=&ctno;
stname system.student.sname%type;
stg system.grade.grade%type;
begin
returns (stno,ctno,stname,stg);
end;
3. 创建一个存储函数:根据给定的部门,返回该部门员工的工资总和
--创建函数
create or replace function sal_sum(dpname system.dept.dname%type)
return system.emp.sal%type
is salary_sum system.emp.sal%type;
begin
select sum(sal)into salary_sum from system.emp,system.dept
where system.dept.dname=dpname and system.emp.deptno= system.dept.deptno;
return salary_sum;
exception
when no_data_found then return 0;
end;
--pL-SQL语句进行调用
declare
dpname system.dept.dname%type:=&dpname;
begin
dbms_output.put_line(dpname||'总工资:'||sal_sum(dpname));
end;
希望对大家有所帮助,不理解的地方可以私信我,我们一起讨论,我也刚开始学不久。谢谢读者。
更多推荐
已为社区贡献2条内容
所有评论(0)