我正在尝试创建一个触发器来自动更新数据库中用户的状态级别。状态级别基于用户生成的收入金额。这就是我到目前为止所提出的。
create or replace trigger update_hirer_status
after insert or update of payment_id, status_id on payments
for each row
declare
user_id_temp number := 0;
total_amount number := 0;
begin
select external_users.external_user_id into user_id_temp
from external_users
join financial_accounts
using (external_user_id)
join payments
on financial_accounts.account_number = payments.sending_account_number
where financial_accounts.account_number = payments.sending_account_number;
select sum(amount) into total_amount
from payments
join
financial_accounts
on payments.sending_account_number = financial_accounts.account_number
join external_users
on financial_accounts.external_user_id = external_users.external_user_id
where payments.status_id = 1
and financial_accounts.external_user_id = user_id_temp;
if total_amount >= 2000
then update external_users
set status_id = 4
where external_user_id = user_id_temp;
elsif total_amount >= 500
then update external_users
set status_id = 3
where external_user_id = user_id_temp;
elsif total_amount >= 100
then update external_users
set status_id = 2
where external_user_id = user_id_temp;
end if;
end;
尝试创建此触发器时,我收到以下错误消息:
第6行出错:PL / SQL:忽略SQL语句
declare
user_id_temp number := 0;
total_amount number := 0;
begin
select external_users.external_user_id into user_id_temp
有谁知道问题可能是什么?这是我第一次尝试创建触发器,因此非常感谢您的反馈。
答案 0 :(得分:1)
问题在于以下陈述
select external_users.external_user_id into user_id_temp
from external_users
join financial_accounts
using (external_user_id)
join payments
on financial_accounts.account_number = payments.sending_account_number
where financial_accounts.account_number = payments.sending_account_number;
USING
子句将EXTERNAL_USERS.EXTERNAL_USER_ID
和FINANCIAL_ACCOUNTS.EXTERNAL_USER_ID
合并到一个EXTERNAL_USER_ID
字段中,因此您无法再说EXTERNAL_USERS.EXTERNAL_USER_ID
。将语句更改为
select external_user_id
into user_id_temp
from external_users
join financial_accounts
using (external_user_id)
join payments
on financial_accounts.account_number = payments.sending_account_number
where financial_accounts.account_number = payments.sending_account_number;
并尝试一下。
分享并享受。