我對Oracle很有點新,我想知道,如果我可以給update statement case
中的變量賦值。我可以爲更新語句中的變量賦值嗎?
我到目前爲止這樣的代碼:
PROCEDURE insert_repayment_data_inst(
date_of_payment_l IN credit_mo_repayment.date_of_payment%TYPE,
amoount_to_pay_l IN credit_mo_repayment.ammount_to_pay%TYPE,
client_number_l IN credit_mo_repayment.client_number%TYPE,
is_paid_l IN credit_mo_repayment.is_paid%TYPE,
month_l IN credit_mo_repayment.is_paid%TYPE,
year_l IN credit_mo_repayment.is_paid%TYPE,
ending_balance_l IN credit_mo_repayment.ending_balance%TYPE,
tests IN credit_mo_repayment.ending_balance%TYPE
) AS
BEGIN
select monthly_installment into tests
from credit_mo_repayment
WHERE (to_char(date_of_payment, 'mm') = to_char(to_date(date_of_payment_l), 'mm'))
AND (to_char(date_of_payment, 'yy') = to_char(to_date(date_of_payment_l), 'yy'));
UPDATE credit_mo_repayment
SET
monthly_installment = CASE
WHEN (Monthly_installment - amoount_to_pay_l >= 0) THEN Monthly_installment - amoount_to_pay_l
WHEN (Monthly_installment - amoount_to_pay_l < 0) THEN 0
END,
ending_balance = CASE
WHEN (Monthly_installment - amoount_to_pay_l < 0) THEN ending_balance - ABS(Monthly_installment - amoount_to_pay_l) tests:= ending_balance - ABS(Monthly_installment - amoount_to_pay_l)
WHEN (Monthly_installment - amoount_to_pay_l >= 0) THEN ending_balance
END,
ammount_to_pay = ammount_to_pay + amoount_to_pay_l
WHERE (to_char(date_of_payment, 'mm') = to_char(to_date(date_of_payment_l), 'mm'))
AND (to_char(date_of_payment, 'yy') = to_char(to_date(date_of_payment_l), 'yy'));
END insert_repayment_data_inst;
正如你可以看到我試圖將值賦給變量的情況下內部這樣 tests:= ending_balance - ABS(Monthly_installment - amoount_to_pay_l)
但沒有運氣。
我也嘗試將monthly_installment
的值分配給tests
變量,然後只是做數學,但我也沒有運氣。
select monthly_installment into tests
from credit_mo_repayment
WHERE (to_char(date_of_payment, 'mm') = to_char(to_date(date_of_payment_l), 'mm'))
AND (to_char(date_of_payment, 'yy') = to_char(to_date(date_of_payment_l), 'yy'));
我知道我在語法中缺少一些東西,但我無法發現它。
當您嘗試選擇測試時出了什麼問題?錯誤信息? – Armunin
@Armunin'錯誤(683,3):PL/SQL:SQL Statement ignored','錯誤(683,35):PLS-00403:expression'TESTS'不能用作SELECT/FETCH語句的INTO目標','錯誤(684,3):PL/SQL:ORA-00904::invalid identifier' – Slim
您確定'tests'的類型正確嗎? 'ending_balance'與'monthly_installment'的類型相同嗎? – Armunin