我有A表成绩
id | Marks
----------------+----------
1 |
2 | 33
for record in (select Marks from grades)
loop
marks=rec.Marks;
if(marks is null) then
marks=0;
end if;
end loop;
我的问题是在if条件下如何写标记的条件是 null,marks是一个整数类型
答案 0 :(得分:2)
如果您想在检索时更改此功能,您还可以使用CASE或COALESCE
SELECT col1, COALESCE(marks, 0) as MARKS from grades
或
SELECT col1, CASE WHEN marks IS NULL THEN 0 ELSE marks END AS marks
FROM grades
答案 1 :(得分:1)
要更改值,请使用update语句:
update grades
set marks = 0
where marks is null;
要插入数据,请使用带有合并的insert
语句:
insert into temp_table (col1, marks)
select col1, coalesce(marks, 0)
from grades;