declare
v_studentid number(5):=10;
v_firstname varchar(20);
begin
select first_name into v_firstname from students where id=v_studentid;
exception
when no_data_found then
insert into log_table(info)
values('student 10 does not found');
end;
v_studentid number(5):=10;
v_firstname varchar(20);
begin
select first_name into v_firstname from students where id=v_studentid;
exception
when no_data_found then
insert into log_table(info)
values('student 10 does not found');
end;
v_studentid number(5):=10; --定义变量,学生ID,并赋值为10
v_firstname varchar(20); --定义字符串变量
begin
--查询students表的first_name字段,条件为学生ID为10,并把结果赋给v_firstname变量
select first_name into v_firstname from students where id=v_studentid;
exception --如果出现异常
when no_data_found then --没有结果返回
insert into log_table(info) --插入错误日志表错误信息
values('student 10 does not found');
end;
declare
v_studentid number(5):=10; -- 定义变量 并赋值为 10
v_firstname varchar(20); -- 定义变量
begin
select first_name into v_firstname from students where id=v_studentid;
-- 从students 表中查出 first_name 放入到变量 v_firstname
exception --异常处理
when no_data_found then -- 没有发现数据
insert into log_table(info) --插入到 日志表里
values('student 10 does not found');
end;
v_studentid NUMBER(5) := 10;--声明一个数字变量并赋初值
v_firstname VARCHAR(20);--声明的一个字符型变量,长度为20
BEGIN
SELECT first_name INTO v_firstname FROM students WHERE id = v_studentid; --从表里查询first_name并赋与变量v_firstname
EXCEPTION --异常处理部分
WHEN no_data_found THEN --如果select...into...没有查询到任何符合条件的记录
INSERT INTO log_table (info) VALUES ('student 10 does not found');--记录异常日志
END;
--你的是一个匿名块
declare
v_studentid number(5):=10;-- 申明变量v_studentid并且值为10
v_firstname varchar(20);--申明变量v_firstname
begin
select first_name into v_firstname from students where id=v_studentid;
--从表students查出id为10的first_name的值插入给变量v_firstname,
--此处的id应该是主键 且对应记录为一条,不然这样就会有问题
exception --异常
when no_data_found then
insert into log_table(info)
values('student 10 does not found');
--没有找到记录则插入到日志表info字段中
end;
v_studentid number(5):=10; --定义变量,学生ID,并赋值为10
v_firstname varchar(20); --定义字符串变量
begin
--查询students表的first_name字段,条件为学生ID为10,并把结果赋给v_firstname变量
select first_name into v_firstname from students where id=v_studentid;
exception --如果出现异常
when no_data_found then --没有结果返回
insert into log_table(info) --插入错误日志表错误信息
values('student 10 does not found');
end;
v_studentid number(5):=10; --定义变量,学生ID,并赋值为10
v_firstname varchar(20); --定义字符串变量
begin
--查询students表的first_name字段,条件为学生ID为10,并把结果赋给v_firstname变量
select first_name into v_firstname from students where id=v_studentid;
exception --如果出现异常
when no_data_found then --没有结果返回
insert into log_table(info) --插入错误日志表错误信息
values('student 10 does not found');
end;