我在编程中不断遇到此问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我在编程中不断遇到此问题相关的知识,希望对你有一定的参考价值。

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

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

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

DECLARE

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;

BEGIN

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表中更新。

答案

您在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 ;

干杯!

以上是关于我在编程中不断遇到此问题的主要内容,如果未能解决你的问题,请参考以下文章

magic number 在编程中是啥意思?

分形在编程中的实际应用

Java开发人员在编程中常见的雷!

除了 AND/OR/NOT,其他逻辑运算符在编程中的意义何在?

javaScript在编程中问题与功能

javaScript在编程中问题与功能