1.txt
来自「4、 编写一个过程。要求:有一个输入参数和一个输出参数」· 文本 代码 · 共 45 行
TXT
45 行
4、 编写一个过程。要求:有一个输入参数和一个输出参数,过程里面要有自定义异常。从学生表中(tab_student)中寻找符合指定学号等于输入参数的值,然后将找到的学生的姓名赋予输出参数,如果没有符合条件的值则触发异常。
Create table tab_student
(sno char(8),
sname varchar2(20),
age integer,
province varchar2(60),
sex char(4))
insert into tab_student values(‘001’,’zhou’,20,’江苏徐州’,’男’);
上述表已经创建,只需针对此表编写即可。
Create table tab_student(
sno char(8),
sname varchar2(20),
age integer,
province varchar2(60),
sex char(4)
);
insert into tab_student values('001','zhou',20,'江苏徐州','男');
create or replace procedure find_student
(i_sno in char , o_sname out varchar )
as
myException exception;
countstudent integer;
var_sname tab_student.sname%type;
begin
select count(*) into countstudent from tab_student where i_sno=sno;
if countstudent>0 then
select sname into var_sname from tab_student where i_sno=sno;
dbms_output.put_line(var_sname);
else
raise myException;
end if;
exception
when myException then
dbms_output.put_line('name not found!');
end find_student;
declare
var_studentname tab_student.sname%type;
begin
find_student('002',var_studentname);
end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?