我在编程中一直遇到这个问题

时间:2019-10-17 01:32:12

标签: oracle oracle11g

交易将从持股中进行 表(NEW_TRANSACTIONS)并插入TRANSACTION_DETAIL和 TRANSACTION_HISTORY表。 适当的帐户余额将是 在ACCOUNT表中更新。

我的代码不断出现此问题:“精确获取返回的行数超过了请求的行数” the table

错误报告- ORA-01422:精确获取返回的行数超过了请求的行数 ORA-06512:第28行 01422. 00000-“精确提取返回的行数超过了请求的行数” *原因:精确提取中指定的数字小于返回的行。 *操作:重写查询或更改请求的行数

声明

r_new_trans NEW_TRANSACTIONS%ROWTYPE;
cursor c_trans_data IS
SELECT UNIQUE transaction_no, transaction_date,description, account_no, transaction_type, transaction_amount
FROM new_transactions;

TYPE UP_ACCOUNT IS RECORD (
      A_NO ACCOUNT.ACCOUNT_NO%type,
      A_TYPE_CODE account.account_type_code%type,
      A_BALANCE account.account_balance%TYPE,
      A_trans_type account_type.default_trans_type%type);

update_a UP_ACCOUNT;

--v_new_trans_amount TRANSACTION_DETAIL.TRANSACTION_AMOUNT%TYPE := 0;
v_new_balance ACCOUNT.ACCOUNT_BALANCE%TYPE := 0; 
v_transaction_debit NEW_TRANSACTIONS.TRANSACTION_TYPE%TYPE := 'D';
v_transaction_credit  NEW_TRANSACTIONS.TRANSACTION_TYPE%TYPE := 'C';
v_transaction_number  new_transactions.transaction_no%TYPE;

v_transaction_variable new_transactions.transaction_no%TYPE := 0;
v_transaction_deta_variable new_transactions.transaction_no%TYPE := 0;  

v_temp_balance account.account_balance%type := 0;

开始

SELECT account_no, a.account_type_code, account_balance, default_trans_type into update_a
FROM ACCOUNT a JOIN ACCOUNT_TYPE at on a.account_type_code = at.account_type_code ;

--/1st cursor/
FOR r_trans IN c_trans_data LOOP
        IF(r_trans.TRANSACTION_NO <> v_transaction_variable)
        THEN 
            INSERT INTO TRANSACTION_HISTORY
            VALUES (r_trans.TRANSACTION_NO, r_trans.TRANSACTION_DATE,r_trans.DESCRIPTION);         
        END IF;
        v_transaction_variable := r_trans.TRANSACTION_NO;
        DBMS_OUTPUT.PUT_LINE('v_transaction_variable');

        IF(r_trans.TRANSACTION_NO <> v_transaction_variable)
        THEN 
            INSERT INTO TRANSACTION_DETAIL
            VALUES (r_trans.ACCOUNT_NO, r_trans.TRANSACTION_NO,r_trans.TRANSACTION_TYPE,r_trans.TRANSACTION_AMOUNT);         
        END IF;
        v_transaction_deta_variable:= r_trans.TRANSACTION_NO;
        DBMS_OUTPUT.PUT_LINE('v_transaction_deta_variable');

        IF r_trans.transaction_type <>  update_a.A_trans_type
            THEN 
            v_temp_balance := v_temp_balance - r_trans.TRANSACTION_AMOUNT;

            UPDATE account 
            SET account_balance = v_temp_balance
            WHERE account_no = r_trans.account_no;

        ELSIF r_trans.transaction_type = update_a.A_trans_type
            THEN 
            v_temp_balance := v_temp_balance + r_trans.TRANSACTION_AMOUNT;

            UPDATE account 
            SET account_balance = v_temp_balance
            WHERE account_no = r_trans.account_no;

        END IF; 
END LOOP;          

END;

交易将从持股中进行 表(NEW_TRANSACTIONS)并插入TRANSACTION_DETAIL和 TRANSACTION_HISTORY表。 适当的帐户余额将是 在ACCOUNT表中更新。

1 个答案:

答案 0 :(得分:0)

您在SELECT .. INTO语句中遇到问题,因为它返回多个记录,并且将其存储在UDT类型的变量中,该变量仅包含1条记录。

您需要声明如下内容:

Type UP_ACCOUNT_TBL IS TABLE OF UP_ACCOUNT index by PLS_INTEGER;
update_a UP_ACCOUNT_TBL;

您的选择查询应如下所示:

SELECT UP_ACCOUNT(account_no, a.account_type_code, account_balance, default_trans_type) into update_a
FROM ACCOUNT a JOIN ACCOUNT_TYPE at on a.account_type_code = at.account_type_code ;

干杯!