sql - 无法从 pl/sql 中的空值获取 NULL
问题描述
在我的表“Group”中,我没有 name=John,所以我想在“new_name”中获取 NULL 值。
SELECT name INTO new_name FROM Group WHERE name="John";
在 pl/sql 中:
if(new_name IS NULL) then ---here is the problem,I can't enter in "if",instead of having name=NULL, I have name=" ",and when I try to use if(new_name=" "), there's an error....---
some code .....
end if;
那么如何检查“if”语句,它是否为NULL(不需要使用EXISTS)?
解决方案
A simple method is to use aggregation:
SELECT MAX(name) INTO new_name
FROM Group
WHERE name = 'John';
An aggregation query with no GROUP BY
is guaranteed to return one row. If all rows are filtered out, then the results of the aggregations are NULL
.
推荐阅读
- excel - 添加唯一值并排除常量值 - 优化公式
- javascript - ASP.NET Core SPA 中基于 JWT 的身份验证 - 前端验证
- c# - Directory.Exists 使用多个斜杠检查路径
- php - 使用 php-fpm 和 mod_proxy 时创建新的命名处理程序
- r - 如何向我显示模式以及模式出现的频率?
- wordpress - 如何在 Dockerfile 中下载和解压
- java - Java:如何使用最佳编码实践设置父和祖父成员变量
- apache-spark - 在 map reduce pyspark 中编写复杂函数
- mariadb - Mariadb Galera Cluster Multi-Master 查询执行速度慢
- c# - 播放列表未播放