oracle - 在 PL/SQL 中向表中插入值
问题描述
由于这个原因,我是 PL/SQL 的新手,很抱歉这个问题很简单。我希望你能帮助我。
我的目标是使用 for 循环向表中添加值。如果您有任何问题,请重播,我会尽快回答。这是我的代码不起作用。
declare
cursor c_exam_info is select result1 from exam_info;
begin
for i IN c_exam_info
loop
if result1>60 then
insert into exam_info(result1) values('pass');
else
insert into exam_info(result1) values('fail');
end if;
end loop;
end;
解决方案
我无法查看图像。
不管怎样:INSERT
似乎不合适——不是UPDATE
更好的选择吗?像这样的东西:
begin
for i IN (select id, result1 from exam_info) loop
update exam_info set
result_type = case when c_exam_info.result1 > 60 then 'pass'
else 'fail'
end
where id = c_exam_info.id;
end loop;
end;
虽然,同样可以在 SQL 层中完成,但您不需要 PL/SQL(除非它是家庭作业,所以您正在练习 PL/SQL)。
update exam_info set
result_type = case when c_exam_info.result1 > 60 then 'pass'
else 'fail'
end;
result1
如果该列 ( ) 是一个数字(例如 60),则用字符串(“失败”或“通过”)更新(甚至插入)同一列没有多大意义。另外,它是什么样的表——只有一列;这样有什么好处INSERT
(你在代码中写的那个)?
推荐阅读
- visibility - 仅在特定时间范围内显示指标
- git - Atom 编辑器仍然允许使用合并和删除的分支
- open-policy-agent - 当数组中的元素时打开策略代理减少数组
- pdf - 如何通过 Latex 将 Jupyter 笔记本转换为 PDF?
- python - 在 Python 中使用 2D 列表:查找匹配和附加字符串
- snakemake - Snakemake 规则没有名为“nbformat.v1.convert”的模块错误
- mysql - mysql ON DUPLICATE KEY UPDATE 的替代解决方案
- python - plt 图像颜色错误
- facebook - 如何获得 Instagram 直接 API 身份验证
- vue.js - Vue + axios:已被 CORS 策略阻止