cursor B1 is select user_id, user_code, user_name, electric_power_ct, elec_number, zone_code from be_user t where t.zone_code = Chzonecode and t.user_type in ('0', '1', '8', '15'); B B1%rowtype;把这段sql中Chzonecode改成if判断不为空的时候才在where后面去匹配
时间: 2023-06-18 14:01:59 浏览: 87
SQL cursor用法实例
5星 · 资源好评率100%
你可以这样修改:
```
IF Chzonecode IS NOT NULL THEN
OPEN B1 FOR
SELECT user_id, user_code, user_name, electric_power_ct, elec_number, zone_code
FROM be_user t
WHERE t.zone_code = Chzonecode AND t.user_type IN ('0', '1', '8', '15');
ELSE
OPEN B1 FOR
SELECT user_id, user_code, user_name, electric_power_ct, elec_number, zone_code
FROM be_user t
WHERE t.user_type IN ('0', '1', '8', '15');
END IF;
FETCH B1 INTO B;
WHILE B1%FOUND LOOP
-- do something with B
FETCH B1 INTO B;
END LOOP;
CLOSE B1;
```
这样修改后,如果Chzonecode为空,就会执行第二个SELECT语句,否则就执行第一个SELECT语句。
阅读全文