THIS IS THE CODE THAT I TRIED
SET SERVEROUTPUT ON;
ACCEPT input_accountNumber NUMBER PROMPT 'Enter the account number : '
ACCEPT input_branch CHAR PROMPT 'Enter the branch : '
CREATE FUNCTION activeAccounts
RETURN NUMBER IS
accountNumber NUMBER;
BEGIN
FOR rec IN (SELECT account_number, branch FROM ACCOUNT_DATA WHERE status='Active')
LOOP
INSERT INTO ACTIVE_ACCOUNTS VALUES (rec.account_number,rec.branch);
END LOOP;
END;
/
DECLARE
accountStatus VARCHAR(20);
inputuser_accountNumber NUMBER;
inputuser_branch VARCHAR(20);
cf varchar(20);
BEGIN
inputuser_accountNumber := '&input_accountNumber';
inputuser_branch := '&input_branch';
SELECT status INTO accountStatus FROM ACCOUNT_DATA;
IF (accountStatus = 'Active') THEN
cf := activeAccounts();
ELSE
DBMS_OUTPUT.PUT_LINE('The account is Inactive.');
END IF;
END;
/
AND THE PROBLEM STATEMENT IS
Write a stored function in PL/SQL for given requirement and use the same in PL/SQL block. Account no. and branch name will be accepted from user. The same will be searched in table acct_details. If status of account is active then display appropriate message and also store the account details in active_acc_details table, otherwise display message on screen “account is inactive”.
AND THE ERROR IS
Error report - ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 9
- 00000 - "exact fetch returns more than requested number of rows" *Cause: The number specified in exact fetch is less than the rows returned. *Action: Rewrite the query or change number of rows requested
returnanything asreturnstatement is missing. If your intention is just to insert records, you can useProcedures. - XING