以下是我的表请求的条件。
level of till 300$ 301-500$ 501-3400$
credit card
usage in
3 month
0% 0% 0% 0%
1-30% 30% 0% 0%
31-50% 50% 0% 0%
51-60% 50% 15% 0%
61-70% 100% 15% 0%
70%~ 100% 30% 30%
我的任务是使用 PL SQL 在一个表中检索我上面提到的所有信息。我有表请求,它由 3 列组成,分别是 client_id、level_3m 和 credit_limit 所以输出(例如)使用上述信息应该如下所示:
level_3m credit_limit($) new_limit(%)
0 50 0
45 400 0
45 250 50
65 350 15
80 1500 30
到目前为止我做了什么?这是我自己的脚本:
DECLARE
v_level VARCHAR2(100);
v_credit_limit VARCHAR2(100);
v_id VARCHAR2(100);
new_limit VARCHAR2(100);
BEGIN
SELECT level_3m,
credit_limit
INTO v_level, v_credit_limit
FROM request a
WHERE v_id = a.client_id;
--this is for "till 300$" condition
IF v_level = 0
AND v_credit_limit =< 300 THEN
new_limit := 0;
ELSIF v_level >= 1
AND v_level <= 30
AND v_credit_limit =< 300 THEN
new_limit := 30;
ELSIF v_level >= 31
AND v_level <= 50
AND v_credit_limit =< 300 THEN
new_limit := 50;
ELSIF v_level >= 51
AND v_level <= 60
AND v_credit_limit =< 300 THEN
new_limit := 50;
ELSIF v_level >= 61
AND v_level <= 70
AND v_credit_limit =< 300 THEN
new_limit := 100;
ELSIF v_level >= 70
AND v_credit_limit =< 300 THEN
new_limit := 100;
END IF;
END;
/
--the other conditions were written same manner as the above one.
我是 PL/SQL 的新手,所以请告诉我我的情况对吗?还是有另一种更简单的方法来编写这些条件?