用oracle编写程序包,包中含有一个过程和一个函数
答案:3 悬赏:20 手机版
解决时间 2021-11-14 13:44
- 提问者网友:太高姿态
- 2021-11-14 07:48
用oracle编写程序包,包中含有一个过程和一个函数
最佳答案
- 五星知识达人网友:醉吻情书
- 2021-11-14 08:28
create or replace package pk2 is
procedure jobs(empid scott.emp.job%type,numbs out number);
function depts(deptid scott.emp.deptno%type) return number;
end pk2;
/
create or replace package body pk2 is
procedure jobs(empid scott.emp.job%type,numbs out number) is
begin
select count(*)
into numbs
from emp
where job = empid;
exception
when others then
numbs := 0;
end;
function depts(deptid scott.emp.deptno%type) return number is
numbs number;
begin
select count(*)
into numbs
from emp
where deptno = deptid;
return numbs;
exception
when others then
return 0;
end;
end pk2;
/
procedure jobs(empid scott.emp.job%type,numbs out number);
function depts(deptid scott.emp.deptno%type) return number;
end pk2;
/
create or replace package body pk2 is
procedure jobs(empid scott.emp.job%type,numbs out number) is
begin
select count(*)
into numbs
from emp
where job = empid;
exception
when others then
numbs := 0;
end;
function depts(deptid scott.emp.deptno%type) return number is
numbs number;
begin
select count(*)
into numbs
from emp
where deptno = deptid;
return numbs;
exception
when others then
return 0;
end;
end pk2;
/
全部回答
- 1楼网友:像个废品
- 2021-11-14 10:56
过程能够输出所有的student表的学生姓名(name字段)和学号(id字段)值。
函数能够根据传入的id参数,检索出该id值对应的学生姓名(name字段值),如果不存在,输出“该学生不存在”
函数能够根据传入的id参数,检索出该id值对应的学生姓名(name字段值),如果不存在,输出“该学生不存在”
- 2楼网友:老鼠爱大米
- 2021-11-14 09:40
create or replace package pk is
procedure p();
function f(i in number);
end pk;
/
create or replace package body pk is
procedure p()
is
cursor c is select id,name from student;
begin
for c_temp in c loop
dbms_out.putline(c_temp.id||c_temp.name);
end loop;
end p;
function f(i in number) return varchar2
is
a varchar2(20);
begin
select max(name) into a from student where id =i;
if a='' then
a='不存在的ID'
end if;
return a;
end f;
end pk;
/
没测试 可以参考下具体要求具体改吧
procedure p();
function f(i in number);
end pk;
/
create or replace package body pk is
procedure p()
is
cursor c is select id,name from student;
begin
for c_temp in c loop
dbms_out.putline(c_temp.id||c_temp.name);
end loop;
end p;
function f(i in number) return varchar2
is
a varchar2(20);
begin
select max(name) into a from student where id =i;
if a='' then
a='不存在的ID'
end if;
return a;
end f;
end pk;
/
没测试 可以参考下具体要求具体改吧
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯